I want to create an indicator of the incumbent House Representative being of the same party as the President ( democrat_pres variable tells if the year has a democrat president or not).
Also, I want to create a competitive indicator which will hold 1 if the democratic vote share is 40-45% , will hold 2 if the democratic vote share is 46-50%, will hold 3 if democratic vote share is 51-55% , will hold 4 if the democratic vote share is 55-60% and will hold 5 if the democratic vote share is 60%.
Can anyone kindly guide me how I can do the above ?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year str20 state byte(district state_fips) str47 party long(candidatevotes totalvotes) float democrat_pres 2016 "ALABAMA" 1 1 "REPUBLICAN" 208083 215893 1 2016 "ALABAMA" 1 1 "" 7810 215893 1 2016 "ALABAMA" 2 1 "REPUBLICAN" 134886 276584 1 2016 "ALABAMA" 2 1 "DEMOCRAT" 112089 276584 1 2016 "ALABAMA" 2 1 "" 29609 276584 1 2016 "ALABAMA" 3 1 "DEMOCRAT" 94549 287104 1 2016 "ALABAMA" 3 1 "REPUBLICAN" 192164 287104 1 2016 "ALABAMA" 3 1 "" 391 287104 1 2016 "ALABAMA" 4 1 "REPUBLICAN" 235925 239444 1 2016 "ALABAMA" 4 1 "" 3519 239444 1 2016 "ALABAMA" 5 1 "REPUBLICAN" 205647 308326 1 2016 "ALABAMA" 5 1 "DEMOCRAT" 102234 308326 1 2002 "CALIFORNIA" 6 6 "REPUBLICAN" 62052 209563 0 2002 "CALIFORNIA" 6 6 "LIBERTARIAN" 4936 209563 0 2002 "CALIFORNIA" 7 6 "REPUBLICAN" 36584 138376 0 2002 "CALIFORNIA" 7 6 "DEMOCRAT" 97849 138376 0 2002 "CALIFORNIA" 7 6 "LIBERTARIAN" 3943 138376 0 2002 "CALIFORNIA" 8 6 "REPUBLICAN" 20063 160441 0 2002 "CALIFORNIA" 8 6 "LIBERTARIAN" 2659 160441 0 2002 "CALIFORNIA" 8 6 "GREEN" 10033 160441 0 2002 "CALIFORNIA" 8 6 "DEMOCRAT" 127684 160441 0 2002 "CALIFORNIA" 8 6 "" 2 160441 0 2002 "CALIFORNIA" 9 6 "DEMOCRAT" 135893 166917 0 2002 "CALIFORNIA" 9 6 "" 6 166917 0 2002 "CALIFORNIA" 9 6 "LIBERTARIAN" 5685 166917 0 2002 "CALIFORNIA" 9 6 "REPUBLICAN" 25333 166917 0 2002 "CALIFORNIA" 10 6 "DEMOCRAT" 126390 167197 0 2002 "CALIFORNIA" 10 6 "LIBERTARIAN" 40807 167197 0 2020 "ARIZONA" 1 4 "REPUBLICAN" 176709 365178 0 2020 "ARIZONA" 1 4 "DEMOCRAT" 188469 365178 0 2020 "ARIZONA" 2 4 "DEMOCRAT" 209945 381054 0 2020 "ARIZONA" 2 4 "REPUBLICAN" 170975 381054 0 2020 "ARIZONA" 2 4 "WRITE-IN (COMMON SENSE MODERATE)" 35 381054 0 2020 "ARIZONA" 2 4 "WRITE-IN (INDEPENDENT)" 99 381054 0 2020 "ARIZONA" 3 4 "REPUBLICAN" 95594 269837 0 2020 "ARIZONA" 3 4 "DEMOCRAT" 174243 269837 0 2020 "ARIZONA" 4 4 "WRITE-IN (INDEPENDENT)" 39 398623 0 2020 "ARIZONA" 4 4 "WRITE-IN (LIBERTARIAN)" 67 398623 0 2020 "ARIZONA" 4 4 "DEMOCRAT" 120484 398623 0 2020 "ARIZONA" 4 4 "WRITE-IN (REPUBLICAN)" 5 398623 0 2020 "ARIZONA" 4 4 "WRITE-IN (INDEPENDENT)" 7 398623 0 2020 "ARIZONA" 4 4 "WRITE-IN (DEMOCRATIC)" 19 398623 0 2020 "ARIZONA" 4 4 "REPUBLICAN" 278002 398623 0 2020 "ARIZONA" 5 4 "REPUBLICAN" 262414 445657 0 end
0 Response to creating a dummy variable based on percentage
Post a Comment