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
Joint modelling of binary longitudinal outcomes in using random effects approachHi everyone, I would like to jointly model two binary repeated outcomes in STATA using the random ef…
Long Data Format: Creating a New Variable with Values Conditional on Combination of Values of Other Variables Across Many ObservationsHello! I am stuck not knowing how to create a variable I need based on my current data. I have a l…
Why is Stata calculating percentiles in the way it does, and who has said that this is the way to calculate percentiles?The definition of a percentile I have been taught, is (1) Q(p) = F^(-1)(p) = inf{x: F(x)>=p}, 0&…
Negative lower confidence interval boundary for variance with nlcom after a multilevel logistic regressionHello, I am conducting a multilevel logistic regression to identify determinants of the availabilit…
total dose per day with multiple dates and times Code: * Example generated by -dataex-. To install: ssc install dataex clear input int(date_daily_3…
Subscribe to:
Post Comments (Atom)
0 Response to foreach and subinstr
Post a Comment