Hello stata community,
I have a problem while creating dummy variables and having the correct name and label. So I have an expenditure dataset with multiple households, consuming multiple goods. Something like that (I put after the : the label of the value given):
Family ID | Expenditure ID (expcode)
1 | 2 : Energy expenditure
1 | 5 : Utilities expenditure
1 | 7 : Food expenditure
2 | 1 : Housing expenditure
2 | 11 : Leisure expenditure
3 | 3 : Clothing expenditure
3 | 8 : Fruits expenditures
3 | 11 : Education expenditure
As showed above, very expenditure ID has a label that corresponds, for example 1 is Housing expenditure, 2 Energy expenditure, 3 Clothing expenditure, etc.
What I would like to do is to create dummy variables for each of the expenditure category that will have:
-As name, the value of the expenditure category with a prefix (like exp_).
-As label, the label of each expenditure category.
Which will translate into something like this for the first dummy variable: exp_1 : Housing expenditures
second dummy var: exp_2 : Energy expenditure
I tried with many different solutions and so far I have managed to generate the variable name correctly with either of these 2 codes:
numlabel, add
dummieslab exp, word(1) template (exp_@)
or
levelsof expcode, local(exp)
foreach i of numlist `exp' {
gen exp_`i'=expcode==`i'
}
but nothing on the label! I tried labelmask, label def and so far no results! If anybody could help me, it would be great, I have more than 500 variables so impossible to do it one by one thank you!
I have a problem while creating dummy variables and having the correct name and label. So I have an expenditure dataset with multiple households, consuming multiple goods. Something like that (I put after the : the label of the value given):
Family ID | Expenditure ID (expcode)
1 | 2 : Energy expenditure
1 | 5 : Utilities expenditure
1 | 7 : Food expenditure
2 | 1 : Housing expenditure
2 | 11 : Leisure expenditure
3 | 3 : Clothing expenditure
3 | 8 : Fruits expenditures
3 | 11 : Education expenditure
As showed above, very expenditure ID has a label that corresponds, for example 1 is Housing expenditure, 2 Energy expenditure, 3 Clothing expenditure, etc.
What I would like to do is to create dummy variables for each of the expenditure category that will have:
-As name, the value of the expenditure category with a prefix (like exp_).
-As label, the label of each expenditure category.
Which will translate into something like this for the first dummy variable: exp_1 : Housing expenditures
second dummy var: exp_2 : Energy expenditure
I tried with many different solutions and so far I have managed to generate the variable name correctly with either of these 2 codes:
numlabel, add
dummieslab exp, word(1) template (exp_@)
or
levelsof expcode, local(exp)
foreach i of numlist `exp' {
gen exp_`i'=expcode==`i'
}
but nothing on the label! I tried labelmask, label def and so far no results! If anybody could help me, it would be great, I have more than 500 variables so impossible to do it one by one thank you!
Comment