Announcement

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

  • summary stats with years

    Dear all,

    do you know if there is a quick and easy way to produce summary stats with a column containing list of all the years in which a variable has observations (no missings)?
    I want it to look like this:

    | N Mean p50 p10 p90 Min Max SD years

    -------+----------------------------------------------------------------------------------------------------------------------------------

    hid | 341487 1304643 510564 33499 3307726 19 5540404 1378070 1984...2022

    solar | 13055 .1162773 0 0 1 0 1 .3205694 2015, 2020
    // hid was part of the questionnaire in every wave of the SOEP between 1984 until 2022
    //solar was part of the questionnaire just in 2015 and 2020

    best regards
    Philipp



  • #2
    Code:
    bys year: mdesc X

    Comment


    • #3
      Philipp:
      as an aside to George's helpful reply, you may want to consider:
      Code:
       use "https://www.stata-press.com/data/r17/nlswork.dta"
      (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
      
      . tabstat ln_wage, stat(count mean sd p10 p50 p90 min max) by(year)
      
      Summary for variables: ln_wage
      Group variable: year (Interview year)
      
          year |         N      Mean        SD       p10       p50       p90       Min       Max
      ---------+--------------------------------------------------------------------------------
            68 |      1375   1.44136  .3884235  .9339457  1.464574  1.885603  .0176546  2.853805
            69 |      1232  1.531032  .3766929  1.114742  1.517537    1.9666  .0240972  3.204134
            70 |      1686  1.507048  .3984743   1.03136  1.517537  1.980921  .0240972  3.005013
            71 |      1851  1.546859   .414415  1.069442  1.542669  2.044887  .0253174  3.285639
            72 |      1693  1.567283  .4319477    1.1191  1.572356  2.099055  .0682788  4.242752
            73 |      1981  1.578448  .4297621  1.158604  1.572356  2.087474  .0080322  3.757158
            75 |      2141  1.579865  .4077728  1.166102  1.571567  2.094945  .0622126  3.925446
            77 |      2171  1.658813  .4308272  1.217396  1.646234  2.200052  .0044871  3.623841
            78 |      1964   1.71629  .4327877  1.209544  1.699692  2.262693  .0684925  4.029306
            80 |      1847  1.729773  .4442248  1.275272  1.702015   2.29097  .1438704  4.199647
            82 |      2085  1.726432    .46796   1.20896  1.702928  2.314513         0  4.254619
            83 |      1987  1.768276  .5140673  1.171759  1.738154  2.405637         0  4.828314
            85 |      2085  1.831842  .5063103  1.184976  1.818867  2.453659  .0300107  4.025415
            87 |      2164  1.841969  .5201446   1.16909   1.83592  2.495166  .0441609  4.005049
            88 |      2272  1.879937  .5960048  1.169571  1.837401  2.553363  .0049397  5.263916
      ---------+--------------------------------------------------------------------------------
         Total |     28534  1.674907  .4780935  1.166102  1.640541   2.27569         0  5.263916
      ------------------------------------------------------------------------------------------
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Dear George,

        this is probably a very useful command. but im not interested in the number of missings.


        Dear Carlo,

        this seems to be more like what I had in mind. But this is still very different than my example in my first post (see below).
        Sorry for my persistence but it is important for me and my colleges to see in the descriptive stats immediately which years of the variables are survey.
        Is this exact way possible in stata (or R, Excel)?

        Click image for larger version

Name:	Screenshot 2022-11-23 at 14.01.15.png
Views:	1
Size:	39.4 KB
ID:	1690673

        Comment


        • #5
          Philipp:
          not that I know.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment

          Working...
          X