Thank you so much for the reply, Clyde! I should have clarified that each year is a stand alone datafile. So the loop would go into something like:
The goal is to go into each year of data, reshape it and create a year variable, then append them all into one panel dataset. Even doing it one by one with the code your provided and changing the year is helpful. but if there is a straightforward way to get above loop to run to come up with that goal, that would be appreciated.
Code:
cd "C:\Users\Elena\Desktop\New folder" local files: dir "." files "*dta" tempfile combined clear save `combined', emptyok foreach f of local files { use `"`f'"', clear ds *2016 //except here would account for the other possible years local stubs `r(varlist)' local stubs: subinstr local stubs "2016" "", all reshape long `stubs', i(person_id) j(year) destring `stubs' , replace gen source_file = `"`f'"' append using `combined' save `"`combined'"', replace } save all_years_data, replace
The goal is to go into each year of data, reshape it and create a year variable, then append them all into one panel dataset. Even doing it one by one with the code your provided and changing the year is helpful. but if there is a straightforward way to get above loop to run to come up with that goal, that would be appreciated.
Comment