Announcement

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

  • Doing a table

    Dear Statalist,
    I need to plot a table with the means of a variable, for all the possible intersection of the year and region (to be plotted on the vertical and on the horizontal axis). To be clear, I just need a simple double entry table, with the years on the vertical axis, the regions on the horizontal one, and the mean values of the x variable inside the table. I tried a couple of option with table tabstat, like

    Code:
      tabstat x, by (year region)
      by year: tabstat x, by (regione)
      table x year region
      by region: table year x
    but I haven't found a satisfying one. The first one returns me an error (too many variables after by) while the second one gives me as many output as the number of years. Table returns me frequencies, and not means. I want a single table, with years and regions on the axis, and mean value of x in the middle. Is possible to obtain it with Stata? Any suggestion about the syntax to adopt? If possible, I'd like to have also the median value. I look at the guide before bothering you, but unfortunately I wasn't able to find what I need. May someone help me?

    Thank to all of you in advance for the patience, and to anyone that will help!

  • #2
    Here is some technique that may be helpful.

    Key points:

    1. You are not limited to the summary statistics that a tabulation command provides. You can calculate your own summaries and then just table them.

    2. People often overlook tabdisp. I made that point in 2003: http://www.stata-journal.com/sjpdf.html?articlenum=pr0010

    See also http://www.stata-journal.com/sjpdf.h...iclenum=pr0053


    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . egen mean = mean(mpg), by(foreign rep78)
    
    . egen median = median(mpg), by(foreign rep78)
    
    . tabdisp foreign rep78, c(mean median)
    
    ----------------------------------------------------------------------
              |                     Repair Record 1978                    
     Car type |        1         2         3         4         5         .
    ----------+-----------------------------------------------------------
     Domestic |       21    19.125        19  18.44444        32     23.25
              |       21        18        19        18        32        24
              | 
      Foreign |                     23.33333  24.88889  26.33333        14
              |                           23        25        25        14
    ----------------------------------------------------------------------
    
    . tabdisp foreign rep78, c(mean median) format(%2.1f)
    
    ----------------------------------------------
              |         Repair Record 1978        
     Car type |    1     2     3     4     5     .
    ----------+-----------------------------------
     Domestic | 21.0  19.1  19.0  18.4  32.0  23.3
              | 21.0  18.0  19.0  18.0  32.0  24.0
              | 
      Foreign |             23.3  24.9  26.3  14.0
              |             23.0  25.0  25.0  14.0
    ----------------------------------------------

    Comment


    • #3
      Nick,
      thank you very much for your answer. I haven't tried yet, I will let you know.

      Comment


      • #4
        Dear Nick, I wasn't aware of tabdisp, and it's wonderful. Unfortunately, I'm not able to export the results in LaTeX. Are you aware of any way or user command to export tabdisp created tables in LaTeX or, at least, Word? Thank you very much!

        V

        Comment


        • #5
          I'd start a new thread. I almost never have cause to do this and you need to get help from people who do.

          Comment


          • #6
            Thank you very much for the support and for showing me a wonderful brand new command!

            Comment

            Working...
            X