Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Summarize mean and std dev by country

    Hello! I have a pooled cross sectional data over a period of 11 years, with 11 different countries. I have tried to summarize so I have the variables and their mean value by country but have not managed to get any of the suggested codes to work to my satisfaction.

    I have 7 different variables that I am interest in getting the mean and std dev of, so the basic descriptive statistics.
    Is there any code that works? It's not a problem if I have to do it 7 different times for each variable.

    Kind regards
    Gabriel



  • #2
    Gabriel:
    welcome to this forum.
    Do you mean something along the following lines?
    Code:
    . use "https://www.stata-press.com/data/r16/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . tabstat tenure hours age, stats(count mean sd) by(race)
    
    Summary statistics: N, mean, sd
      by categories of: race (race)
    
      race |    tenure     hours       age
    -------+------------------------------
     white |     19859     20133     20165
           |  3.098138  36.14439  29.10865
           |  3.727851  10.45539   6.78639
    -------+------------------------------
     black |      7941      8034      8042
           |  3.196942   37.5824  28.85663
           |  3.825786  8.092534  6.483481
    -------+------------------------------
     other |       301       300       303
           |  2.890642     37.03  29.81848
           |  3.267122  10.68032  6.505478
    -------+------------------------------
     Total |     28101     28467     28510
           |  3.123836  36.55956  29.04511
           |  3.751409  9.869623  6.700584
    --------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Welcome to Statalist.

      Perhaps this example will start you in a useful direction.
      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . by foreign, sort: summarize price weight length
      
      ------------------------------------------------------------------------------------------------
      -> foreign = Domestic
      
          Variable |        Obs        Mean    Std. Dev.       Min        Max
      -------------+---------------------------------------------------------
             price |         52    6072.423    3097.104       3291      15906
            weight |         52    3317.115    695.3637       1800       4840
            length |         52    196.1346    20.04605        147        233
      
      ------------------------------------------------------------------------------------------------
      -> foreign = Foreign
      
          Variable |        Obs        Mean    Std. Dev.       Min        Max
      -------------+---------------------------------------------------------
             price |         22    6384.682    2621.915       3748      12990
            weight |         22    2315.909    433.0035       1760       3420
            length |         22    168.5455    13.68255        142        193
      If this doesn't help, please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

      The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

      Section 12.1 is particularly pertinent

      12.1 What to say about your commands and your problem

      Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
      ...
      Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

      Comment


      • #4
        7 variables * (mean, SD) * 11 countries could be 7 tables or 11 tables or .... (Same with 11 years, perhaps less likely to be what you want.)

        Not clear to me what you seek here.

        Comment


        • #5
          Originally posted by Carlo Lazzaro View Post
          Gabriel:
          welcome to this forum.
          Do you mean something along the following lines?
          Code:
          . use "https://www.stata-press.com/data/r16/nlswork.dta"
          (National Longitudinal Survey. Young Women 14-26 years of age in 1968)
          
          . tabstat tenure hours age, stats(count mean sd) by(race)
          
          Summary statistics: N, mean, sd
          by categories of: race (race)
          
          race | tenure hours age
          -------+------------------------------
          white | 19859 20133 20165
          | 3.098138 36.14439 29.10865
          | 3.727851 10.45539 6.78639
          -------+------------------------------
          black | 7941 8034 8042
          | 3.196942 37.5824 28.85663
          | 3.825786 8.092534 6.483481
          -------+------------------------------
          other | 301 300 303
          | 2.890642 37.03 29.81848
          | 3.267122 10.68032 6.505478
          -------+------------------------------
          Total | 28101 28467 28510
          | 3.123836 36.55956 29.04511
          | 3.751409 9.869623 6.700584
          --------------------------------------
          
          .
          Originally posted by William Lisowski View Post
          Welcome to Statalist.

          Perhaps this example will start you in a useful direction.
          Code:
          . sysuse auto, clear
          (1978 Automobile Data)
          
          . by foreign, sort: summarize price weight length
          
          ------------------------------------------------------------------------------------------------
          -> foreign = Domestic
          
          Variable | Obs Mean Std. Dev. Min Max
          -------------+---------------------------------------------------------
          price | 52 6072.423 3097.104 3291 15906
          weight | 52 3317.115 695.3637 1800 4840
          length | 52 196.1346 20.04605 147 233
          
          ------------------------------------------------------------------------------------------------
          -> foreign = Foreign
          
          Variable | Obs Mean Std. Dev. Min Max
          -------------+---------------------------------------------------------
          price | 22 6384.682 2621.915 3748 12990
          weight | 22 2315.909 433.0035 1760 3420
          length | 22 168.5455 13.68255 142 193
          If this doesn't help, please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

          The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

          Section 12.1 is particularly pertinent

          Originally posted by Nick Cox View Post
          7 variables * (mean, SD) * 11 countries could be 7 tables or 11 tables or .... (Same with 11 years, perhaps less likely to be what you want.)

          Not clear to me what you seek here.

          I apologize for the unclarity, and very thankful for trying to help despite. I kind of solved this by using by finding estout.

          Code:
           estpost tabstat GINI MI, by(Country) statistics(mean sd)
          I will further add 5 more variables to the list, but for the sake of clarity...

          This produced

          Code:
               Country |   e(GINI)      e(MI)
          -------------+----------------------
          1            |                      
                  mean |   .501748   9.348204
                    sd |  .0437604   1.959797
          -------------+----------------------
          2            |                      
                  mean |   .534551   .8567287
                    sd |  .0159864    .428698
          -------------+----------------------
          3            |                      
                  mean |  .5356355   4.654319
                    sd |  .0129177   1.159286
          -------------+----------------------
          4            |                      
                  mean |  .4892817     .42632
                    sd |  .0082746   .1302424
          -------------+----------------------
          5            |                      
                  mean |  .4780821   3.270388
                    sd |  .0215088   1.653508
          -------------+----------------------
          6            |                      
                  mean |  .4859275   6.076411
                    sd |   .030521   2.458783
          -------------+----------------------
          7            |                      
                  mean |  .4409624   2.512615
                    sd |    .02471   .4413849
          -------------+----------------------
          8            |                      
                  mean |  .5430072   2.195497
                    sd |  .0314899   .1946327
          -------------+----------------------
          9            |                      
                  mean |   .520281   .7124343
                    sd |  .0121104   .3464067
          -------------+----------------------
          10           |                      
                  mean |  .5039686   8.369864
                    sd |  .0204749   3.724086
          -------------+----------------------
          11           |                      
                  mean |  .4639318   10.75843
                    sd |  .0283073   2.813741
          -------------+----------------------
          Total        |                      
                  mean |  .4997615   4.471019
                    sd |  .0388631   3.925899
          A problem that I encountered after, was when I tried to export it to word using estab

          Code:
           esttab using Table3.rtf, replace main (mean) b(a3) aux(sd) title(Table 1: Summarystatistics) nogap mtitles(GINI MI )
          The output is very weird.

          Basically, each number represents one country, and the variables presented becomes the average for all the 11 years that I have data over. I would like to present this in a nice word document to put in my thesis.

          Kind regards!

          P.s I will read the FAQ now, sorry for the unclear thread!
          Last edited by Gabriel Antoine; 21 May 2020, 11:07.

          Comment

          Working...
          X