Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73258

Generating a binary variable conditional on multiple values from another variable, to create Southern and Northern states.

$
0
0
I have a set of survey data, where I have the "Statefip code" for the US state an individual lives in. I want to create two binary variables:

1) NorthernStates: which has a value of 1 if they live in a "northern" state, and 0 otherwise
2) SouthernStates: which has a value of 1 if they live in a "southern state, and 0 otherwise

ID Statefip Northern Southern
234 1 0 1
546 12 0 1
876 18 1 0
432 33 1 0
156 6 0 0


The definition I'm using for Southern state is when Statefip equals 1, 5, 12, 13, 22, 28, 37, 45, 47, 48, 51. These numbers correspond to Alabama, Arkansas, Florida, Georgia, Louisiana, Mississippi, North Carolina, South Carolina, Tennessee, Texas, Virginia.


The definition I'm using for Northern state is when Statefip equals 9, 10, 17, 18, 23, 24, 25, 26, 33, 34, 36, 39, 42, 44, 50, 55. These numbers correspond to delaware, Illinois, Indiana, Maine, Maryland, Massachusetts, Michigan, New Hampshire, New Jersey, New York, Ohio, Pennsylvania, Rhode Island, Vermont, Wisconsin.

So for a west-coast or midwestern state (for example, California where Statefip==6) would equal 0 for both Southern and Northern variables.


Does anyone have a more elegant way to create these variables than me manually creating dummies for each state, and then adding them up to create the Southern and Northern states.


Viewing all articles
Browse latest Browse all 73258

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>