Announcement

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

  • Summarize for second level only

    Dear all,

    I would like to ask you wheter it is possible to get information (mainly about number of observation but also mean, SD etc.) from second level variables only.

    I am working with pane-level data (2 levels) and when I use -sum- command I get information per every single observation, but I'd like to get this information from the second level only (country level in my case). So the information from 1st level cases agregates to the second level. Is that possible?

    Thank you for your help.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte countrylevel double A_90ss int democracy double enep
     1   9.29 45     3.17
     1  9.563 49     3.87
     1  3.825 50     3.59
     1   9.29 54     3.82
     1 18.579 57     3.02
     1  5.464 61     3.71
     1 14.208 63     4.79
     1 10.929 68 5.149357
     1  16.94 72        .
     2   5.66 45     9.81
     2  4.597 49     9.35
     2  7.667 53    10.29
     2 11.667 57     8.84
     2 10.667 61     9.04
     2 14.333 64    10.04
     2  9.333 68 9.447867
     5  8.929 21     3.67
     5  3.571 26     3.79
     5  4.464 31     3.76
     5  8.036 36     4.29
     5  5.357 41     3.85
    end
    From this example you can see there is about 20 observations, but when we get to the upper level there are only 3.
    Last edited by Karel Novak; 14 Mar 2019, 08:52.

  • #2
    Karel:
    do you mean something like this?
    Code:
    . tabstat A_90ss democracy enep, stat(count mean sd p50 min max) by( countrylevel)
    
    Summary statistics: N, mean, sd, p50, min, max
      by categories of: countrylevel
    
    countrylevel |    A_90ss  democr~y      enep
    -------------+------------------------------
               1 |         9         9         8
                 |  10.89867  57.66667   3.88992
                 |  4.911337  9.082951  .7366895
                 |     9.563        57     3.765
                 |     3.825        45      3.02
                 |    18.579        72  5.149357
    -------------+------------------------------
               2 |         7         7         7
                 |     9.132  56.71429   9.54541
                 |  3.431241  8.260635  .5275389
                 |     9.333        57  9.447867
                 |     4.597        45      8.84
                 |    14.333        68     10.29
    -------------+------------------------------
               5 |         5         5         5
                 |    6.0714        31     3.872
                 |  2.311473  7.905694  .2425283
                 |     5.357        31      3.79
                 |     3.571        21      3.67
                 |     8.929        41      4.29
    -------------+------------------------------
           Total |        21        21        20
                 |  9.160429        51  5.864861
                 |     4.242  14.04991  2.824607
                 |      9.29        53      4.08
                 |     3.571        21      3.02
                 |    18.579        72     10.29
    --------------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Hello, this is unfortunately a little bit different than what I am trying to achieve. For example, the tab shows number of cases (9, 7, 5) from chosen variables at given country level. What I want to know is the information from second level only, so in the last tab "Total" it should show N=3, because only 3 countries were in dataset (and in each country it should have been N=1).

      //edit: But yes, the mean values etc. are correct, I just want to get the last thing and it is the number of observations at the second level, if that is possible of course. Thank you for your help.
      Last edited by Karel Novak; 14 Mar 2019, 12:04.

      Comment


      • #4
        Karel:
        have you considered -collapse-?
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment


        • #5
          Oh, thank you. I actually didn't use this command in the past, I find it very useful for my purpose.

          Comment

          Working...
          X