I have 3 separate variables for education created in my dataset which is the number of non-veterans in a county that had either a high school, some college or college or more education from 2012-2016. I am hoping to create a categorical variable called "educ" that would be a combination of these three variables.
I tried using the following format for generating a new variable but i haven't had any luck:
gen educ=1 if nonvetedu_hs>1
replace educ=2 if nonvetedu_hsplus>1
replace educ=3 if nonvetedu_college>1
replace educ=4 if nonvetedu_hs<. & nonvetedu_hsplus<. & nonvetedu_college<.
My goal is to create categorical variables for similar other variables (race, gender, income, etc) which are all formatted the same way so that I can use it in regression model. I included the three variables of interest plus the year variable. I previously reshaped from wide to long and the data for 2013-2016 is missing. Not sure how I fix this (or if i need to fix this) for the model ...but I will follow up on that in a separate post.
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long(nonvetedu_college nonvetedu_hsplus nonvetedu_hs) byte year
. . . 10
. . . 11
6783 26851 4274 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
35408 107434 13014 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
2074 12031 4616 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
1667 11594 2881 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
4499 27648 7355 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
672 4530 2397 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
1996 10117 2482 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
11694 55134 13080 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
2574 17094 4404 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
2293 13272 3196 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
. . . 11
3855 21120 5630 12
. . . 13
. . . 14
. . . 15
. . . 16
. . . 17
. . . 18
. . . 10
end
0 Response to Creating a categorical variable from multiple numeric variables
Post a Comment