Announcement

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

  • TABSTAT: How to group my summary statistics?

    Hello together.

    I need help and search for a simple way to "group" my summary statistics.

    My current Stata code is as follows: by year,sort :tabstat variable1 variable2 , s(n mean ...)

    It gives me the number of observations and mean as output for each year...

    ... however, I now like to group the years by let's say (2000, 2001, 2002 and 2003) and (2004, 2005, 2006, 2007).

    Is there an easy way to do this without creating new variables?

    Thank you!

    Konstantin

  • #2
    Is there an easy way to do this without creating new variables?
    No, but there is an easy way to create the single new variable that is needed.
    Code:
    recode year (2000/2003 = 1 "2000 to 2003") (2004/2007 = 2 "2004 to 2007"), generate(group)
    by group, sort: tabstat ...
    will create the variable "group" taking the value 1 or 2, with value labels so they display nicely.

    Comment


    • #3
      Also, tabstat allows for the if condition. This way, we won't need to create new variables.

      That said, William Lisowski 's rendition is more elegant.
      Best regards,

      Marcos

      Comment


      • #4
        Thanks for your help!

        Comment

        Working...
        X