Home › Forums › ASDOC : Easy Publication Quality Tables in Stata › asdoc: using two variables with bysort for summary statistics
Tagged: asdoc, bysort, Stata, summary statistics, two variables
-
AuthorPosts
-
Aamina Khurram
GuestMarch 26, 2020 at 11:51 amPost count: 118Dear Dr. Attaullah Shah
I hope you are in good health. As you would remember Could you please see the request below.
I am running the following command in stata but it does not work to output using asdoc
bysort Country IDType: sum Var1
when I use the same code without asdoc command, it says too many variables stated, although the output is otherwise produced by stata.
I particularly want an output using this command:
bysort Country IDType: asdoc sum Var1
I believe this is something that asdoc fails to output.
It would be kind enough if you can clarify this bit.
Thanking in anticipation
Currently, asdoc allows bysort prefix with only one variable. If you need to use two variables with bysort, then there is a workaround. Convert both the variables to a single with using the group function of egen, and then use the new variable with asdoc. see this example
egen Ctry_ID= group(Country IDType) bysort Ctry_ID: asdoc sum Var1
Please cite asdoc in your research.
In-text citation
Tables were created using asdoc, a Stata program written by Shah (2018).Bibliography
Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.Aamina Khurram
GuestMarch 26, 2020 at 11:23 pmPost count: 118Dear Dr. Atta,
Indeed the code apparently seems to solve the problem but is limited in displaying the complete information. It only displays the numbers as 1,2,3 for the grouping variables in Country_ID, which is not if much use. In simple words I need the output as below:
summary stats of Var1(Profit) of Country & ID_Type Country ID_type Banks(Profit) Real Estate (Profit) ___________________________________________________________ N, Mean, SD, min max N, Mean, SD, min max _______________________________ _____________________ Bahrain 11 6 Bangladesh 8 1 Egypt 14 2 Indonesia 16 0 Jordan 126 2 Total xyz xyz _________________________________________________________
However, I get the output from the above given code in #3193 as:
_____________________________________________________ ID N mean sd min max _____________________________________________________ 1 264 .233 .497 -1.999 2.387 10 77 .13 .332 -.751 .745 2 279 .197 .366 -1.999 1.918 3 294 .109 .149 -.785 .584 4 31 .188 .072 .025 .358 5 275 .189 .26 -.743 .996 6 82 -.064 .277 -1.339 .329 7 857 .099 1.243 -6.832 29.043 8 0 . . . . 9 631 -.002 .394 -1.999 1.865 __________________________________________________
What I need is the depiction of my country and ID types in the first column here which is just shown as numbers. I hope there shall be some way to get around this. Because The number of ID_type I have is more than 600, it is not very convenient to do this manually.
Kind Regards:
AaminaPerhaps you need to use the
tabstat
command for this. tabstat is more flexible thansum
command. And even you can give a try to thetable
command.Aamina Khurram
GuestApril 1, 2020 at 8:37 pmPost count: 118Dear Dr Attaullah Shah
Thanks for your reply. Unfortunately neither tabstat nor Table seems to give me what is required in #3197. The output is shown perfect by stata without using asdoc with this code:
bysort Country IDType: sum Var1
but does not give me the desired presentation in Word when I use the same command with asdoc.
See this example
sysuse auto, clear bysort foreign rep78 : sum price table foreign rep78, contents(freq mean price sd price min price min price ) asdoc table foreign rep78, contents(freq mean price sd price min price min price ) replace ------------------------------------------------------------ | Repair Record 1978 Car type | 1 2 3 4 5 ----------+------------------------------------------------- Domestic | 2 8 27 9 2 | 4,564.5 5,967.6 6,607.1 5,881.6 4,204.5 | 522.5519 3579.357 3661.267 1592.019 311.8341 | 4,195 3,667 3,291 3,829 3,984 | 4,195 3,667 3,291 3,829 3,984 | Foreign | . . 3 9 9 | . . 4,828.7 6,261.4 6,292.7 | . . 1285.613 1896.092 2765.629 | . . 3,895 3,995 3,748 | . . 3,895 3,995 3,748 ------------------------------------------------------------ *And using tabstat by foreign, sort : tabstat price, statistics( count mean sd min min ) by(rep78)
-
This reply was modified 3 years, 6 months ago by
Attaullah Shah.
-
This reply was modified 3 years, 6 months ago by
Attaullah Shah.
Aamina Khurram
GuestApril 2, 2020 at 11:24 pmPost count: 118Dear Dr Attaullah Shah
Thanks a lot for your assistance on this matter. But the asdoc code with Table is giving errors.
asdoc table foreign rep78, contents(freq mean price sd price min price min price ) replace
It says 0000006 not found. error r(111).
Any thing to fix this?
Best
AaminaAamina Khurram
GuestApril 2, 2020 at 11:31 pmPost count: 118Also with your tabstat code:
*And using tabstat by foreign, sort : tabstat price, statistics( count mean sd min min ) by(rep78)
where can we put asdoc to get the output?
Best
Aamina-
This reply was modified 3 years, 5 months ago by
Attaullah Shah.
I just checked the following and works fine. Do you have an updated copy of asdoc? You can check by
which asdoc asdoc table foreign rep78, contents(freq mean price sd price min price max price ) replace ------------------------------------------------------------ | Repair Record 1978 Car type | 1 2 3 4 5 ----------+------------------------------------------------- Domestic | 2 8 27 9 2 | 4,564.5 5,967.6 6,607.1 5,881.6 4,204.5 | 522.5519 3579.357 3661.267 1592.019 311.8341 | 4,195 3,667 3,291 3,829 3,984 | 4,934 14,500 15,906 8,814 4,425 | Foreign | . . 3 9 9 | . . 4,828.7 6,261.4 6,292.7 | . . 1285.613 1896.092 2765.629 | . . 3,895 3,995 3,748 | . . 6,295 9,735 11,995 ------------------------------------------------------------
Aamina Khurram
GuestApril 4, 2020 at 3:44 amPost count: 118Dear Dr Attaullah Shah
I just checked, the asdoc version I have is the latest one, I had copied from the link you gave me above:
Version 2.3.7.3 : Changes made on April 1, 2020 : Fixed bug in ttest by(vars)
I am still getting errors to export the Table to asdoc, it is otherwise produced by Stata.
Aamina Khurram
GuestApril 4, 2020 at 3:47 amPost count: 118Dear Dr Attaullah
Thank you so much, I just checked again and the error was resolved once I restarted Stata.
Best Regards,
Aamina
-
This reply was modified 3 years, 6 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.