Hello all. I'm having issues on generating a new variable with multiple values. I'm using Stata 15.1 for Windows.
I have a variable, state, which has observations for eight US states. Initially they were string variables, so I converted them to new variables. It gave each state a value from 1 to 8.
I would like to generate a variable, charteryear, equal to a year when the state is 3 (Florida, for example). I ran it and it stopped after the first line.
I'd like charteryear to have a value for all 8 states. Below is what I ran:
g charteryear = 18 if state == 1
g charteryear = 14 if state == 2
g charteryear = 20 if state == 3
g charteryear = 18 if state == 4
g charteryear = 18 if state == 5
g charteryear = 13 if state == 6
g charteryear = 17 if state == 7
g charteryear = 21 if state == 8
Also, can I run this with my state as a string variable? It is easier to remember 3 = Florida for example.
Thank you.
I have a variable, state, which has observations for eight US states. Initially they were string variables, so I converted them to new variables. It gave each state a value from 1 to 8.
I would like to generate a variable, charteryear, equal to a year when the state is 3 (Florida, for example). I ran it and it stopped after the first line.
I'd like charteryear to have a value for all 8 states. Below is what I ran:
g charteryear = 18 if state == 1
g charteryear = 14 if state == 2
g charteryear = 20 if state == 3
g charteryear = 18 if state == 4
g charteryear = 18 if state == 5
g charteryear = 13 if state == 6
g charteryear = 17 if state == 7
g charteryear = 21 if state == 8
Also, can I run this with my state as a string variable? It is easier to remember 3 = Florida for example.
Thank you.
Comment