Announcement

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

  • Generate pseudo-panel out of defined cohorts

    I have repeated cross-sectional observations from a survey that ran from 2010 to 2016. Suppose I'm interested in making a psuedo-panel, using region and birth year as cohorts. I want to get the cohort mean of x1, x3, x3 (some relevant variables.).

    How would I go about doing this cleanly?

    For reference, *age_cohort* and *region_cohort* are my cohort variables, with cohorts numbered 0-3. And *year* is year the survey was conducted.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double caseid long year byte region float(birth_year x1 x2 x3 age_cohort region_cohort)
    20100101100020 2010 3 1983 175  48.11478 4.7088127 3 3
    20100101100045 2010 2 1990 362  82.99108  5.856155 3 1
    20100101100050 2010 4 1941 300  72.08434  5.535239 0 3
    20100101100053 2010 2 1979 678 132.86858  7.069178 3 1
    20100101100087 2010 3 1947 325  76.54424  5.669765 0 3
    end
    label values region region_lbl
    label def region_lbl 2 "Midwest", modify
    label def region_lbl 3 "South", modify
    label def region_lbl 4 "West", modify
    Last edited by John Biton; 18 Oct 2017, 15:07.

  • #2
    One possibility is to generate a variable that combines age_cohort and region_cohort, and then use tabstat.
    Code:
    egen cohort=concat(region_cohort age_cohort)
    tabstat x1 x2 x3, by(cohort) statistic(mean)
    For your sample data I get:
    Code:
    Summary statistics: mean
      by categories of: cohort 
    
    cohort |        x1        x2        x3
    -------+------------------------------
        13 |       520  107.9298  6.462667
        30 |     312.5  74.31429  5.602502
        33 |       175  48.11478  4.708813
    -------+------------------------------
     Total |       368   82.5206   5.76783
    --------------------------------------

    Comment


    • #3
      Hi German,

      Thanks for the response. That's close to what I want. But I'd like to take those collapsed variables and save them for each year. So for instance, I'd like to have the
      Code:
      cohort 13 average of x1 for 2010
      ,
      Code:
      cohort 13 average for x1 for 2011
      , etc.

      Would you know how I handle that? Thanks so much for your response.

      Comment


      • #4
        Not clear to me if you want one table with all the years, in which case you could try

        Code:
        table cohort, contents(mean x1 mean x2 mean x3) by(year)
        Or a separate table for each year, which you could do with

        Code:
        bysort year: tabstat x1 x2 x3, by(cohort) statistic(mean)
        Of course your sample data has only one year

        Comment


        • #5
          Thanks for the response. I ended up doing this before you responded:
          Code:
          foreach var of varlist x1 x2 x3{
          
          bys year cohort: egen cohortavg_`var' = mean(`var')
          }
          Last question on this matter. The concat command was great and worked fine. It's just that when looking at the data, the concat labels are not readily decipherable. Is there any way to leverage a command that serves the same function, yet maintains the labels on both age_cohort, region_cohort? (Note: Apologies for the confusion here, but on my actual dataset, age_cohort does have labels so let us pretend that is so with the sample data.)

          In the egen documentation, it makes it clear that LABEL is not an argument for CONCAT, so I'm looking for some alternate way to get a variable that represents the interaction of the two cohorts.
          Last edited by John Biton; 19 Oct 2017, 17:03.

          Comment


          • #6
            OK, wasn't clear to me that you wanted to save the means as new variables in the dataset. In that case you probably don't need the combined cohort variable.

            To answer the question, however, concat has a decode option that uses the labels instead of the values. You can also define a separator. Try
            Code:
            egen scohort = concat(region_cohort age_cohort), decode punct("_")

            Comment


            • #7
              Hi German,

              That's exactly what I was looking for. Thanks a lot!

              Comment

              Working...
              X