Greetings:
Question: I want to generate a variable in my dataset that is the value of an existing variable but a future value.
Unsure of how to build the syntax of "gen var = electoraltier if yearofparliament is plus 4" for instance. (I'm trying to create a prospective electoral tier [how they ran in next election] for each elected official. Obviously I'll have missing values at the end for this new variable, but that's the next step to worry about)
My dataset goes to 2021, so just a short example above, of course.
Appreciate any suggestions.
Question: I want to generate a variable in my dataset that is the value of an existing variable but a future value.
Unsure of how to build the syntax of "gen var = electoraltier if yearofparliament is plus 4" for instance. (I'm trying to create a prospective electoral tier [how they ran in next election] for each elected official. Obviously I'll have missing values at the end for this new variable, but that's the next step to worry about)
* Example generated by -dataex-. For more info, type help dataex
clear
input str28 mspname float(yearofparliament electoraltier)
"Canavan, Dennis" 1999 4
"Goldie, Annabel" 1999 3
"Scanlon, Mary" 1999 3
"Fergusson, Alex" 1999 3
"Johnstone, Alex" 1999 3
"Wallace, Ben" 1999 3
"Monteith, Mr Brian" 1999 3
"Davidson, Mr David" 1999 3
"McLetchie, David" 1999 3
clear
input str28 mspname float(yearofparliament electoraltier)
"Canavan, Dennis" 1999 4
"Goldie, Annabel" 1999 3
"Scanlon, Mary" 1999 3
"Fergusson, Alex" 1999 3
"Johnstone, Alex" 1999 3
"Wallace, Ben" 1999 3
"Monteith, Mr Brian" 1999 3
"Davidson, Mr David" 1999 3
"McLetchie, David" 1999 3
My dataset goes to 2021, so just a short example above, of course.
Appreciate any suggestions.
Comment