asdocx: Export from Stata to Word, Excel, LaTeX & HTML Forums asdocx Forum Use asdocx in a loop for summary statistics

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Dolorence Okullo
    Participant
    Post count: 1

    HI Attaullah,

    I would like to loop over a number of variables and produce a summary that excludes certain data elements. This is the command I am using, but I would still like to get one table instead of separate tables. how can I do this?

    Thanks

    foreach var in x1 x2 x3 x4{
     asdocx summarizevar if(`var' !=9997) 
    }
    Attaullah Shah
    Moderator
    Post count: 76

    This is possible with flexmat. I encourage you to invest an hour or less on flexmat, and shall have the freedom to make sophisticated tables. Here is a starting blog post https://asdocx.com/flexmat-create-flexible-tables-in-stata-mata/. Let me show an example for creating your desired table.

     sysuse auto , clear 
     loc NextRow 2 
     flexmat reset 
     flexmat addrow , data(Variable , Obs , Mean , Std. dev. , Min , Max) row(1)
     
     foreach var in price mpg trunk {
       sum `var' if `var' != 999
       flexmat addrow , data(`r(N)',`r(mean)',`r(sd)', `r(min)',`r(max)' ) row(`NextRow') dec(3) 
       loc ++NextRow 
      } 
     asdocx export
    Table: Results
    Variable Obs Mean Std. dev. Min Max
    price 74 6165.257 2949.496 3291 15906
    mpg 74 21.297 5.786 12 41
    trunk 74 13.757 4.277 5 23
    Notes:
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.