Announcement

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

  • Reshaping long data with mtultiple categories into long data

    Stata 14.0 SE on Mac - Data contais 700,000 obervations

    Hi. I am trying to reshape a panel of US county population data organised by county and year (data post below)
    (fips) is the unique county indicator, (year) is the year indicator and each fips/year has 19 age categories (agegroup).
    The seven population variables are currenntly orgaised as: total (tot_pop), total male (tot_male), total females (tot_female)...etc.

    What I would like is one observation per fips/year for each combination of age-braket/population-variables. So a total of 133 variables.
    i.e. population aged 85+ (a_85_tot_pop),female white population aged 75-80 (a_75_80_wa_female), etc.

    I am confused about how to use the reshape commands to achieve this task as it seems l likely have to take my data to wide view, and then back to long view but not sure where to begin here.

    In reshape command: i(varname) would include fips s_id c_id year. I'm not sure how to go about identifying the j(varname). (agegroup) is currently string data, while (agegrp) is a numerical indicator for (agegroup)
    fips s_id c_id year agegrp agegroup tot_pop tot_male tot_female wa_male wa_female ba_male ba_female
    2180 2 180 2000 17 80-84 58 27 31 3 4 0 0
    2180 2 180 2001 17 80-84 58 27 31 3 4 0 0
    32027 32 27 2002 18 85+ 58 24 34 24 34 0 0
    2185 2 185 2003 16 75-80 58 18 40 0 2 0 0
    Any help is greatly appreciated,
    Thanks,
    Mike
    Last edited by Mike McRae; 04 Mar 2021, 17:10. Reason: This issue hae been resolved

  • #2
    This issue has been resolved

    Comment


    • #3
      To help others, do you mind explaining how you resolved the issue?

      Comment


      • #4
        From memory I needed to reshape to wide view while keeping my ID and year variables as the row vectors. The code would have looked somehting like:

        reshape wide agegrp, i(fips s_id c_id year) j(tot_pop tot_male tot_female wa_male wa_female ba_male ba_female)

        Comment

        Working...
        X