Dear all,
I am a STATA-beginner and am currently struggling with creating a categorical variable that depends on 3 conditions.
My goal is the following:
I want to create a variable that indicates whether the observation (firm data) is part of a group based on 3 conditions - the country group, the industry, and the size of the firm.
CountryGroup is a variable indicating 1 to 4, Size is a variable indicating 1 to 4, and Industry is a variable that holds the industry code (27 different industries).
For now, my only option to create a variable that indicates each optional combination is as follows:
>generate Category=1 if Industry==15 & Size==1 & CountryGroup==1
>replace Category=2 if Industry==15 & Size==1 & CountryGroup==2
>replace Category=3 if Industry==15 & Size==1 & CountryGroup==3
>replace Category=4 if Industry==15 & Size==1 & CountryGroup==4
>replace Category=4 if Industry==15 & Size==2 & CountryGroup==1
....
Is there a way to code this in a more efficient way than to write (4x4x27) lines of code? So far, I've only found solutions for categorical variables that indicate 0 / 1 or categorical variables that only depend on one condition.
Thanks a lot!
Dana
0 Response to Creating a categorical variable with several conditions
Post a Comment