maldini425
maldini425

Reputation: 317

Labelling Subgroups in a String variable (Stata)

I am trying to label subgroups within a string categorical variable: I have a sex variable stored in "double" format and to make it easier to use in graphs, I converted the variable into string as below

tostring sex, gen(sex_str)

And then I wanted to label the groups following instructions here, and it worked:

label define sex_strlabel 1 "Male" 2 "Female" 

However, when I ran the code below I got this error message "may not label strings"

label values sex_strsex_strlabel 

Upvotes: 0

Views: 269

Answers (1)

Bicep
Bicep

Reputation: 1103

If you need sex in a string format, I would do it like this:

clear

input double sex
1
2
end

label define x1 1"Male" 2"Female"
label value sex x1

decode sex, gen(sex_string)

Upvotes: 2

Related Questions