/*** NOTE: THIS CODE IS NOT USED! It was commited to SVN because it might be useful in the future. ***/ /** Prepares Census population projections minus migration for comparison to 2004 stock population cohort simulation Projection year is specified through PROJYEAR argument. This works for the 2012 and 2017 projections. 2017 is the latest available at this time. */ global projyear : env PROJYEAR log using logs/census_proj$projyear.log, replace /*** prepare Census migration projections (so we can subtract from pop size estimates) ***/ insheet using /sch-data-library/public-data/Census/${projyear}_Pop_Projection/NP${projyear}_D4.csv desc * NOTE: the 2012 file has race_hisp as the variable name while 2017 has race_his (no 'p' at the end) keep if race_his == 0 & inlist(sex,1,2) keep year sex nim_* reshape long nim_, i(year sex) j(age) rename nim_ netmigration desc keep year age sex netmigration li if age==85 * expand migration to age 100 assuming zero net migration at ages 85+ * we do this because the migration table ends at the age 85+ category drop if age==85 expand 17 if age==84, gen(post85) bys sex year age post85: replace age = age + _n if post85==1 replace netmigration = 0 if age >= 85 li if age >=84 drop post85 * set up cumulative migration gen birthcohort = year - age sort sex birthcohort year by sex birthcohort: gen cummigration = sum(netmigration) li tempfile migrationproj save `migrationproj' /*** load Census projections, subtract migration, and collapse to age range of 2004 stock FEM cohort in each simulation year ***/ clear insheet using /sch-data-library/public-data/Census/${projyear}_Pop_Projection/NP${projyear}_D1.csv desc keep if origin == 0 & race == 0 & inlist(sex,1,2) keep year sex pop_* reshape long pop_, i(year sex) j(age) rename pop_ popsize desc tab year sex /* Instead of doing the following, we are now assuming zero net migration after age 85 * migration numbers end in the age 85+ category, so we need to collapse projections for the oldest ages into an 85+ bucket preserve keep if age >= 85 collapse (sum) popsize, by(year sex) gen age = 85 tempfile popsize85p save `popsize85p' restore drop if age >= 85 append using `popsize85p' sort year sex age * li if age > 80 */ * drop year 2016 because there are no net migration numbers available drop if $projyear==2017 & year==2016 * merge on net migration and subtract because we are not doing migration in the FEM merge 1:1 year sex age using `migrationproj' tab _merge li if _merge==1 li if _merge==2 keep if _merge==3 gen sexlab = "M" if sex==1 replace sexlab = "F" if sex==2 drop sex rename sexlab sex * subtract out migration, but only after 2004 because the 2004 stock population weights would include net migrantion replace popsize = popsize - cummigration if year > 2004 gen stockagemin = 51 + year - 2004 /* not doing this anymore * ages 85+ are lumped together so we can't get a population total once the youngest of the stock pop passes age 85 drop if stockagemin > 85 */ replace popsize = 0.0 if age < stockagemin collapse (sum) stockpopsize=popsize (first) stockagemin, by(year sex) rename stockpopsize stockpopsize_census keep year sex stockagemin stockpopsize_census * drop odd-numbered years that are not simulated in FEM drop if mod(year,2) == 1 * rescale census projection counts to 1000s in order to match FEM scale replace stockpopsize_census = stockpopsize_census / 1000.0 save data/census_proj$projyear.dta, replace