Hi,
I am fairly new to stata and am trying to figure out a way where I can recode variables across multiple datasets and have the new recoded variables be saved into 1 aggregate data file. For context, I have 14 files all named: file_1.dta , file_2.dta, .... file_14.dta
For this example, I have a variable MCREV06 where the 06 is the given year
Code:
cd "/Users/octavio/Desktop/MEPS"
clear
foreach i in file_1.dta file_2.dta file_3.dta file_4.dta file_5.dta file_7.dta file_8.dta file_9.dta file_10.dta file_11.dta file_12.dta file_13.dta file_14.dta {
use file_`i'.dta
keep MCREV`num'
gen EVERMEDICARE=0
replace EVERMEDICARE=1 if MCREV`num'==1
append using file_`i'
save aggregatedatafile
}
Related Posts with Append and recode multiple datasets at once
Options in a Panel data regression using Sergio Correia's ''reghdfe''Hello, I am currently working with a panel, using Correia's reghdfe command. Suppose I have a panel…
Sorting observations and keeping oneHi, I would like to ask again the same question for sorting the observations by descending orders a…
Fractional Polynomials - Code for Fp plotHi all, I am trying to understand the non-linear relationship of age in my model using fractional p…
Panel count dataDear Statalists, I’d appreciate your thoughts & help to overcome a roadblock: I have count data…
New package invdesc on SSC Thanks as always to Kit Baum, a new package invdesc is now available for download from SSC. In Stat…
Subscribe to:
Post Comments (Atom)
0 Response to Append and recode multiple datasets at once
Post a Comment