Dear all,
I edit my question and upload again.
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 (abcd_1727_1822_15s2d625j2_GROUP_MOD1-RPT_MOD1 [1])
and for household_income.dta, it has mod2 at the end of they key variable (abcd_1727_1822_15s2d625j2_GROUP_MOD2-RPT_MOD2 [1]),
even if these two are the same observation.
In order to unify this key variable, I want to remove that "_GROUP_MOD1-RPT_MOD1" using looping. I want to keep the rest and that [1] as well. That number after MOD is differed by file, and the number in the [ ] is differed by observation.
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 Removing part of string variable (looping, multiple data files)
IV with fixed effect for data which has not a traditional panel structureHow can I run an IV model with fixed effect in a non-panel dataset? I know that in case of panel dat…
Difficulty generating a conditional variableI'm working with some data on NFL players. I want to create a set of variables that captures the inf…
xtoverid, noi after ec2sls: endogenous variable(s) collinear with instrumentsDear Stata community, I am running ec2sls model: xtivreg investment ( bribery = elf (time invariant…
Interpreting Interaction Effect over TimeHello everyone, I hope you all are having a wonderful week (and weekend)! I have a quick question r…
xtabond2 with sub-periodsHello everyone I hope that you're doing very well I have a panel data for 35 countries from 1985 to …
Subscribe to:
Post Comments (Atom)
0 Response to Removing part of string variable (looping, multiple data files)
Post a Comment