Dear all,
I am currently working on multiple data files in a folder.
For every files, there is a variable "key" which is identifier for observations.
The thing is the key variable has a different number in the observation per data files.
ex) for household_education.dta, it has mod1 at the end of the key variable (4237491637219_mod1)
and for household_income.dta, it has mod2 at the end of they key variable (4237491637219_mod2),
even if these two are the same observation.
In order to unify this key variable, I want to remove the mod1 and mod2 using looping. I used the following code so far, but I am stuck on the "#", where it should be 1 or 2 in my example. what should I put instead of #? Do I just need to type these one by one?
foreach file of local filelist_household_baseline {
use "`file'", clear
replace key = subinstr(key, "GROUP_MOD#-RPT_MOD#", "", .)
save, replace
clear
}
Kind regards,
Hyungwoo
Related Posts with foreach and subinstr
Looping with both `var' and `i' simultaneouslyHello, I want to loop over my variable list, but also be able to have a number `i' that reflects th…
I would like some help with coding and generating faultline variable in StataHello everyone, I'm a student and I'm currently having some issues with coding and generating the v…
Fixed and random effects WITHOUT using clustered robust standard errors (CRSE)Hi Statalist users. I'm new to this forum and would love to get some help from you guys. I'm worki…
Panel data regression with T>NDear STATA users, I am writing my bachelor thesis and need to do some econometric research with sta…
Looping through a list of strings; combining variables within stringsI have a series of household consumption surveys, each for every year, and I want to process each fi…
Subscribe to:
Post Comments (Atom)
0 Response to foreach and subinstr
Post a Comment