Hi,
I am quite new to looping in Stata. While I could actually rename groups of variables through the rename command, I still would like to learn how to do it by looping.
n the codes below, I am trying to rename the variables in "food" to the actual name of the crops. However, my codes are not working. Hoping that someone could point out to me where I got it wrong.
local crop "cereal root fruit meat dairy fish cocoa nonalc foodnes alc tobacco"
local food "i1t_11100 i1t_11200 i1t_11300 i1t_11400 i1t_11500 i1t_11600 i1t_11700 i1t_11800 i1t_11900 i1t_13000 i1t_14000"
foreach x of varlist `food' {
rename `X' t_`crop'
}
I am quite new to looping in Stata. While I could actually rename groups of variables through the rename command, I still would like to learn how to do it by looping.
n the codes below, I am trying to rename the variables in "food" to the actual name of the crops. However, my codes are not working. Hoping that someone could point out to me where I got it wrong.
local crop "cereal root fruit meat dairy fish cocoa nonalc foodnes alc tobacco"
local food "i1t_11100 i1t_11200 i1t_11300 i1t_11400 i1t_11500 i1t_11600 i1t_11700 i1t_11800 i1t_11900 i1t_13000 i1t_14000"
foreach x of varlist `food' {
rename `X' t_`crop'
}
Comment