Hello,
I have a data set with a number of variable labels that I would like to change in a loop. The variable labels have the text "${g0yx}" which I would like to replace with "crop". Please see example below:
What I have now:
Var 1 label: How much ${g0yx} was saved for seed?
Var 2 label: How much ${g0yx} was sold for seed?
What I want to have:
Var 1 label: How much crop was saved for seed?
Var 2 label: How much crop was sold for seed?
The code I have right now is:
foreach i of varlist * {
local a : var label `i'
local a = subinstr("`a'","${g0yx}","crop",.)
label var `i' "`a'"
}
When I run that code, the "${g0yx}" is removed but is not replaced with "crop". Any suggestions on how to fix this?
Many thanks,
Jowel
I have a data set with a number of variable labels that I would like to change in a loop. The variable labels have the text "${g0yx}" which I would like to replace with "crop". Please see example below:
What I have now:
Var 1 label: How much ${g0yx} was saved for seed?
Var 2 label: How much ${g0yx} was sold for seed?
What I want to have:
Var 1 label: How much crop was saved for seed?
Var 2 label: How much crop was sold for seed?
The code I have right now is:
foreach i of varlist * {
local a : var label `i'
local a = subinstr("`a'","${g0yx}","crop",.)
label var `i' "`a'"
}
When I run that code, the "${g0yx}" is removed but is not replaced with "crop". Any suggestions on how to fix this?
Many thanks,
Jowel
Comment