******************************************************* *This do file is a solution to the Panel Conditioning *exercise from the 2018 IPUMS-CPS Summer Data Workshop * *Written by the IPUMS-CPS team *31 May 2018 ******************************************************* cap log close log using logs/08_panel_conditioning.log, t replace set more off local extract_num 00227 qui{ /*pull in data*/ cd data qui do cps_`extract_num'.do noisily: di "...now we have IPUMS data ready to go" noisily: list cpsidp mish age sex in 1/10 numlabel , add noisily: di "...recode empstat into employed, unemployed, and nilf categories" gen empstat_rec = 1 if empstat==10 | empstat==12 replace empstat_rec = 2 if empstat==21 | empstat==22 replace empstat_rec = 3 if empstat==32 | empstat==34 | empstat==36 replace empstat_rec = 0 if empstat == 0 /*Question 2*/ noisily: di "...recoded empstat and mish by month" svyset[weight=wtfinl] noisily: svy: tab empstat_rec mish, count format(%10.0f) /*Question 3*/ di "...for each month, tab recoded empstat by mish" noisily: svy: tab empstat_rec mish if month==12, count format(%10.0f) noisily: svy: tab empstat_rec mish if month==1, count format(%10.0f) noisily: svy: tab empstat_rec mish if month==2, count format(%10.0f) /*make a long file - restrict focal month to mis1 and 2, other months to mis1 and mis2 respectively*/ noisily: di "...keep mish 1 and 2 for all three months" noisily: keep if (month==12 & mish==1) | (month==01 & (mish==1 | mish==2)) | (month==02 & mish==2) noisily: di "...link the file long ways...index and count...you know this by now!" bysort cpsidp (year month) : gen time = _n egen count = max(time),by(cpsidp) noisily: list cpsidp mish age sex time count in 1/10 di "...keep those that appear twice" noisily: keep if count==2 di "...validate!" qui do ../validate_long.txt 2 noisily: tab all_match di "...keep only those that match on all characteristics" noisily: keep if all_match==1 di "...and keep only the records from january" noisily: keep if month==1 di "...finally, remove those who are NIU for empstat" noisily: keep if empstat_rec != 0 /*Question 5*/ noisily: svy: tab empstat_rec mish, count format(%10.0f) /*Question 7*/ noisily: di "...keep only those that respond for themselves (drop proxy responses)" noisily: keep if lfproxy == 1 noisily: svy: tab empstat_rec mish, count format(%10.0f) cd .. log close }