Dear all,
I'm currently at a stumbling block on a Stata code I'm working on. This involves seven different variables with years from 1999 - 2016 and each year is saved as a temp file. Below is code for the years 1999 and 2000 for one variable, to show you how it's structured;
I will need help appending all the years for each variable and finally merging all the variables into one huge data file.
I'm currently at a stumbling block on a Stata code I'm working on. This involves seven different variables with years from 1999 - 2016 and each year is saved as a temp file. Below is code for the years 1999 and 2000 for one variable, to show you how it's structured;
Code:
*importing the matching worksheet in excel file for 1999*
import excel "$data/1999", clear sheet("I.A.2") cellrange(A2:B53) firstrow
*Create year FIPSCode variable*
gen FIPSCode=_n
label var FIPSCode "FIPSCode"
gen Year = 1999
label var Year "Year"
rename JobSearchRequired JobSrchRq
/*Replacing the empty cells with "n/a" and rewriting the state D.C. as DC for
consistency across years*/
replace JobSrchRq = "N/A" if JobSrchRq =="*"
replace State = "DC" if State=="D.C."
*Rearranging the order of data set *
order FIPSCode State Year JobSrchRq
/*Save as a temporary dta file; the format will be temp'year ''a', where'a'
represents the variable Mandatory Job Search at Application variable.*/
sort FIPSCode Year
tempfile temp1999a
save `temp1999a'
*importing the matching worksheet in excel file for 2000*
import excel "$data/2000", clear sheet("I.A.2") cellrange(A2:B53) firstrow
*Renaming Job Search Required variable*
rename JobSearchRequired JobSrchRq
*Rewriting the State D.C. as DC for consistency across years.*
browse
replace State = "DC" if State=="D.C."
/*Removing super scripts which import as numbers attached to the content in the
Job Search Required field*/
tab JobSrchRq
replace JobSrchRq = "Yes" if substr(JobSrchRq,1,1)=="Y"
replace JobSrchRq = "No" if substr(JobSrchRq,1,1)=="N"
*Check to make sure super scripts were actually taken out*
tab JobSrchRq
*Create year FIPSCode variable*
gen FIPSCode=_n
label var FIPSCode "FIPSCode"
gen Year = 2000
label var Year "Year"
*Rearranging the order of data set *
order FIPSCode State Year JobSrchRq
/*Save as a temporary dta file; the format will be temp'year ''a', where'a'
represents the variable Mandatory Job Search at Application variable.*/
sort FIPSCode Year
tempfile temp2000a
save `temp2000a'

Comment