******************************************************* *This do file is a solution to the Estimating Gross Flows *exercise from the 2018 IPUMS-CPS Summer Data Workshop * *Written by the IPUMS-CPS team *31 May 2018 ******************************************************* clear set more off qui{ log using logs/06_gross_flows.log, t replace local exnum 00190 cd data qui do cps_`exnum'.do cd .. noisily: di "...now we have IPUMS data ready to go" noisily: list cpsidp mish age sex in 1/10 noisily: di "...sort, generate index, generate count variables" bysort cpsidp (mish): gen time=_n egen count=max(time),by(cpsidp) noisily: list cpsidp mish age sex time count in 1/10 noisily: di "...validate!" do validate_long.txt 2 /*answer questions 1 and 2*/ noisily: di "...count the number of mechanical matches - be sure to limit to time == 1 to avoid double counting!" noisily: count if count==2 & time==1 noisily: di "...count the number of valid matches - be sure to limit to time == 1 to avoid double counting!" noisily: count if count==2 & all_match==1 & time==1 noisily: di "...keep only observations that are available at both time points and have validated links" keep if count==2 & all_match==1 noisily: count if time==1 noisily: di "...create variables for universe restriction" egen minage=min(age),by(cpsidp) egen minempstat=min(empstat),by(cpsidp) noisily: di "...keep only those age 16+ who were employed, at work, at at least one time point" noisily: keep if minage>=16 noisily: keep if minempstat>1 noisily: di "...recode empstat into gross flows categories" // employed gen empsimp=1 if empstat==10 | empstat==12 // unemployed replace empsimp=2 if empstat>=20 & empstat<30 // not in the labor force replace empsimp=3 if empstat>=30 & empstat!=. label def empsimplbl 1 "employed" 2 "unemployed" 3 "NILF" label val empsimp empsimplbl noisily: tab empstat empsimp, mi noisily: di "...create T1 and T2 employment status varaibles" gen empsimpT1=empsimp if time==1 replace empsimpT1=empsimp[_n-1] if time==2 gen empsimpT2=empsimp if time==2 replace empsimpT2=empsimp[_n+1] if time==1 label def emplbl 1 "employed" 2 "unemployed" 3 "NILF" label val empsimpT1 empsimpT2 emplbl noisily: di "...check to make sure that T1 and T2 empstat variable creation worked properly" egen minempsimpT1=min(empsimpT1),by(cpsidp) egen maxempsimpT1=max(empsimpT1),by(cpsidp) assert minempsimpT1==maxempsimpT1 noisily: di "...a crosstab of the recoded employment status variables at T1 and T2 shows employment transitions" noisily: tab empsimpT1 empsimpT2 if time==2 /*analysis for question 3*/ noisily: di "...weighted counts of employment transitions - be sure to limit to only one time point do avoid double counting!" svyset [weight=panlwt] noisily: svy, subpop(if time==2): tab empsimpT1 empsimpT2, count format(%10.0f) log close }