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
Imputation QuestionHello everyone,
I am performing time series analysis. I have performed multiple imputation on only …
Get latitude using IP addressHi all,
I want to pull latitude/longitude from IP addresses using:
Code:
geocode_ip
ip_address, …
New Stata module for nonparametric errors-in-variables regressionA new Stata module for estimation of nonparametric errors-in-variables (EIV) regression (and constru…
CHAID decision tree to determine significant cutoff of continuous variableI am using Stata 13 SE and have installed the chaid and chaidforest packages. I have a dataset of pa…
Computing percentilesThis may be widely known, but in case not I thought I would share...
Stata has several commands tha…
Subscribe to:
Post Comments (Atom)
0 Response to foreach and subinstr
Post a Comment