Hi, I am trying to label a large number of variables using variable names and labels which are present as variables within the dataset (merged from a different dta). I am labelling different subsets of the dataset at a time based on prefixes contained within the variable names. However, when I run the code, it does not complete - there is no error, it just never stops showing the red cross in the command screen. I have tried leaving it for a long time.
I was hoping someone could help me in either identifying the issue in my code, or suggesting a less computationally intensive way of doing this. The code ran and labelled variables before I added the code relating to filtering by prefix.
EXAMPLE DATASET
MY CODE:
I would be extremely grateful for your help! Thanks.
I was hoping someone could help me in either identifying the issue in my code, or suggesting a less computationally intensive way of doing this. The code ran and labelled variables before I added the code relating to filtering by prefix.
EXAMPLE DATASET
Code:
clear input e_var1 e_var2 e_var3 c_var1 c_var2 c_var4 e_var5 str10 varname_EVAR str10 varlabel_EVAR str10 varname_CVAR str10 varlabel_CVAR 1 1 1 1 1 1 1 var1 evar1lab var1 cvar1lab 1 1 1 1 1 1 1 var2 evar2lab var2 cvar2lab 1 1 1 1 1 1 1 var3 evar3lab var4 cvar4lab 1 1 1 1 1 1 1 var5 evar5lab 1 1 1 1 1 1 1 end
Code:
foreach study in "e" "c" { local studyprefix = "`study'" local studyid = cond("`studyprefix'" == "e", "EVAR", cond("`studyprefix'" == "c", "CVAR", "inhouse")) // studyid local to link to study prefix (ignore inhouse, relevant for real dataset) ** label var local i 1 // i is obs number ds `study'* local varlist_`studyid' `r(varlist)' while !missing("=varname_`studyid'[`i']") { foreach var of varlist `varlist_`studyid'' { local variablename = "`var'" local variablename_nopre = regexr("`variablename'",".*_","") if varname_`studyid'[`i'] == "`variablename_nopre'" { lab var `var' "=varlabel_`studyid'[`i']" } } local ++i } }
Comment