Hi all!
*Using STATA16
I have a cross-sectional dataset with 100 observations and 736 variables. These variables are duplicated, some are strings, and others are numeric. For example, country_str (the string variable) and country_num (the numeric variable).
I´ve been trying to label the values of the numeric variables by using the values of the string ones. For that, I saw the command lab mask. My problem is that I trying to make a loop by using locals and labsmask, but after some hours of trying, asking work colleagues, and looking on the internet I thought it might be easier to ask here.
This is the code:
Thank you very much!
*Using STATA16
I have a cross-sectional dataset with 100 observations and 736 variables. These variables are duplicated, some are strings, and others are numeric. For example, country_str (the string variable) and country_num (the numeric variable).
I´ve been trying to label the values of the numeric variables by using the values of the string ones. For that, I saw the command lab mask. My problem is that I trying to make a loop by using locals and labsmask, but after some hours of trying, asking work colleagues, and looking on the internet I thought it might be easier to ask here.
This is the code:
Code:
:
*1. Create a local containing only numeric variables
ds *_num
local numeric `r(varlist)'
display "`numeric'"
*2. Create a local containing only string variables
ds *_str
local string `r(varlist)'
display "`string'"
*3. Label values of variables with a loop
foreach x in $numeric {
foreach y in $string {
labmask `x', values (`y')
}
}
Thank you very much!


Comment