******************************************************* *This do file is a solution to the Time in the CPS *exercise from the 2018 IPUMS-CPS Summer Data Workshop * *Written by the IPUMS-CPS team *31 May 2018 ******************************************************* qui{ clear set more off log using logs/02_counting_times.log, t replace local exnum 00184 cd data qui do cps_`exnum'.do noisily: di "...now we have IPUMS data ready to go." noisily: list cpsidp month mish age sex in 1/10 noisily: di "...sort by cpsidp and mish to put all appearances of an individual in order" sort cpsidp mish noisily: list cpsidp month mish age sex in 1/10 save extract, replace noisily: di "...and generate a new variable to indicate how many times an individual appears in the data" bysort cpsidp (mish): gen index=_n noisily: list cpsidp month mish age sex index in 1/10 /*Question 1. count based on max of MISH*/ noisily: di "...generate a flag that uses MISH as the basis for counting the number of times an individual appears in the data" egen num_mish=max(mish),by(cpsidp) noisily: list cpsidp month mish age sex num_mish in 1/20 noisily: di "...note the number of times each individual seems to appear in the linked data" noisily: tab num_mish if index==1 /*Question 1. count based on max of INDEX*/ noisily: di "...generate a flag that uses the index variable you created as the basis for counting the number of times an individual appears in the data" egen num_index=max(index),by(cpsidp) noisily: list cpsidp month mish age sex num_index in 1/20 noisily: di "...note the number of times each individual seems to appear in the linked data" noisily: tab num_index if index==1 noisily: di "A crosstab of the index-based count and the MISH-based count shows that MISH is not a reliable indicator of the number of times an individual has appeared in the CPS." noisily: di "This is due to the fact that some individuals may respond in the first and last month, but not all months in between or that individuals may enter the rotation after the household is first surveyed." noisily: tab num_index num_mish if index==1 /*Question 2. count those in second half of rotation*/ noisily: di "To count the number of respondents with an MISH value from the second half of the CPS rotation in 2017..." noisily: di "...generate a flag for an individuals first appearance (their minimum MISH value)" egen first_2017_mish = min(mish),by(cpsidp) noisily: list cpsidp month mish age sex first_2017_mish in 1/20 noisily: di "...and for their final appearance (their maximum MISH value)" egen last_2017_mish = max(mish),by(cpsidp) noisily: list cpsidp month mish age sex first_2017_mish last_2017_mish in 1/20 noisily: di "...generate a flag for those who have MISH values from the second half of the rotation" gen second_halfers = 1 if first_2017_mish >=5 replace second_halfers = 1 if first_2017_mish < 5 & last_2017_mish > 4 replace second_halfers = 0 if second_halfers==. noisily: list cpsidp month mish age sex first_2017_mish last_2017_mish second_halfers in 1/20 noisily: di "The following tabs show the first and last MISH values for each record in 2017." noisily: tab first_2017_mish second_halfers if index==1 noisily: tab last_2017_mish second_halfers if index==1 log close cd .. }