Dear Stata Forum Users,
I would be extremely grateful if anyone could help with this.
I would like to check if female newcomer candidates are selected for less winnable seats than male newcomer candidates.
For winnability, I would like to use the margin by which a candidate’s opposing party won or lost the previous election in the district. I was then planning to conduct a ttest.
I would also like a variable to measure the margin by which a candidate’s own party won or lost the previous election.
But, I cannot correctly create these variables.
I have the following variables: sex, year, prev_election, seito_r (party), vote (%), district_smd (district), status (newcomer, incumbent, previously elected).
The three parties in the analysis:
LDP 1996-2024
2000-2012 DPJ
2017-2024 CDP
I will post my latest (failed) do file below and data below.
I am using Stata19.
Sincerely,
Gill Steel
************************************************** *
* party labels
************************************************** *
gen str3 party = ""
replace party = "LDP" if seito_r == 46
replace party = "DPJ" if seito_r == 42
replace party = "CDP" if seito_r == 35
************************************************** *
* opposition vote share in previous election by district
************************************************** *
gen prev_opp_voteshare = .
* Assign previous opposition vote share based on the election year
foreach year in 2000 2003 2005 2009 2012 2014 2017 2021 2024 {
* Determine opposition party (DPJ or CDP)
local opp = cond(`year' < 2017, "DPJ", "CDP")
* previous opposition vote share for the relevant district and year
bysort str_district (year): replace prev_opp_voteshare = voteshare if year == `year' & party == "`opp'"
}
************************************************** *
* Keep only LDP newcomers (status == 0)
************************************************** *
keep if seito_r == 46 & status == 0
************************************************** *
* confirm `prev_opp_voteshare`
************************************************** *
summ prev_opp_voteshare
I would be extremely grateful if anyone could help with this.
I would like to check if female newcomer candidates are selected for less winnable seats than male newcomer candidates.
For winnability, I would like to use the margin by which a candidate’s opposing party won or lost the previous election in the district. I was then planning to conduct a ttest.
I would also like a variable to measure the margin by which a candidate’s own party won or lost the previous election.
But, I cannot correctly create these variables.
I have the following variables: sex, year, prev_election, seito_r (party), vote (%), district_smd (district), status (newcomer, incumbent, previously elected).
The three parties in the analysis:
LDP 1996-2024
2000-2012 DPJ
2017-2024 CDP
I will post my latest (failed) do file below and data below.
I am using Stata19.
Sincerely,
Gill Steel
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte sex int year float prev_election long(seito_r vote district_smd) byte status 0 2005 2003 46 82486 1 0 0 2012 2009 46 77215 1 0 0 1996 . 46 72178 2 0 0 2000 1996 46 57047 2 0 0 2024 2021 46 59529 2 0 0 2005 2003 46 105631 3 0 0 2012 2009 46 91164 3 0 0 2012 2009 46 91816 4 0 0 1996 . 46 80629 5 0 0 2012 2009 46 98670 5 0 0 2021 2017 46 120203 5 0 0 2005 2003 46 78561 6 0 0 2012 2009 46 71881 6 0 0 2000 1996 46 96086 7 0 0 2012 2009 46 73521 7 0 0 2000 1996 46 47269 9 0 0 2003 2000 46 56472 9 0 0 2005 2003 46 87804 9 0 1 2009 2005 46 58225 9 0 0 2012 2009 46 67086 9 0 0 2021 2017 46 79418 9 0 0 2005 2003 46 86426 10 0 0 2012 2009 46 77700 10 0 0 2024 2021 46 54199 10 0 0 2003 2000 46 79749 11 0 1 2005 2003 46 87824 11 0 0 2012 2009 46 63932 11 0 0 1996 . 46 46485 12 0 0 2009 2005 46 88964 12 0 0 2012 2009 46 67218 12 0 0 1996 . 46 59631 13 0 0 2003 2000 46 80700 13 0 0 2005 2003 46 126670 13 0 0 1996 . 46 49727 14 0 0 2000 1996 46 83601 14 0 0 2000 1996 46 84641 15 0 0 2005 2003 46 123280 15 0 0 1996 . 46 58059 16 0 0 2012 2009 46 93757 16 0 0 2012 2009 46 73356 17 0 0 2005 2003 46 53555 18 0 0 2009 2005 46 92600 18 0 0 2024 2021 46 65200 18 0 0 2012 2009 46 73237 20 0 0 1996 . 46 63672 21 0 0 2021 2017 46 126137 21 0 0 2017 2014 46 128740 22 0 0 1996 . 46 70590 23 0 0 2009 2005 46 94820 24 0 0 2012 2009 46 69927 24 0 0 2024 2021 46 69563 25 0 0 2012 2009 46 75152 28 0 0 2021 2017 46 100227 28 0 0 2024 2021 46 51723 29 0 0 2012 2009 46 100551 30 0 0 1996 . 46 73254 31 0 0 2000 1996 46 95311 31 0 0 1996 . 46 73792 32 0 0 2000 1996 46 76067 32 0 0 2003 2000 46 80051 32 0 0 2005 2003 46 128890 32 0 0 2014 2012 46 67600 32 0 0 2017 2014 46 61804 32 0 0 2003 2000 46 64393 33 0 0 2005 2003 46 132691 33 0 0 1996 . 46 60801 34 0 0 1996 . 46 71306 35 0 0 2003 2000 46 83899 35 0 0 2005 2003 46 118801 35 0 0 2009 2005 46 104262 35 0 0 1996 . 46 69539 36 0 0 2024 2021 46 59070 36 0 0 1996 . 46 75667 37 0 0 2012 2009 46 80024 37 0 0 2024 2021 46 65963 37 0 0 2021 2017 46 119633 38 0 0 2009 2005 46 79924 40 0 0 2012 2009 46 71033 40 0 0 2021 2017 46 76263 40 0 0 2021 2017 46 81015 41 0 0 2000 1996 46 61707 42 0 1 2005 2003 46 51242 42 0 0 1996 . 46 48762 44 0 0 2000 1996 46 81698 44 0 0 1996 . 46 56748 45 0 0 2000 1996 46 68483 45 0 0 2003 2000 46 53611 45 0 0 2005 2003 46 92891 45 0 0 2012 2009 46 96706 45 0 0 2024 2021 46 54186 46 0 0 1996 . 46 42152 47 0 0 2000 1996 46 65838 47 0 0 2012 2009 46 105493 48 0 0 2012 2009 46 118299 49 0 0 1996 . 46 86765 50 0 0 2012 2009 46 86039 50 0 0 2024 2021 46 105563 51 0 0 1996 . 46 71742 52 0 0 2012 2009 46 96172 53 0 0 2005 2003 46 171507 56 0 end label values sex gender_label label def gender_label 0 "Male", modify label def gender_label 1 "Female", modify label values seito_r seito_r label def seito_r 46 "自民", modify label values district_smd district_smd label def district_smd 1 "aichi_1", modify label def district_smd 2 "aichi_10", modify label def district_smd 3 "aichi_11", modify label def district_smd 4 "aichi_12", modify label def district_smd 5 "aichi_13", modify label def district_smd 6 "aichi_14", modify label def district_smd 7 "aichi_15", modify label def district_smd 9 "aichi_2", modify label def district_smd 10 "aichi_3", modify label def district_smd 11 "aichi_4", modify label def district_smd 12 "aichi_5", modify label def district_smd 13 "aichi_6", modify label def district_smd 14 "aichi_7", modify label def district_smd 15 "aichi_8", modify label def district_smd 16 "aichi_9", modify label def district_smd 17 "akita_1", modify label def district_smd 18 "akita_2", modify label def district_smd 20 "aomori_1", modify label def district_smd 21 "aomori_2", modify label def district_smd 22 "aomori_3", modify label def district_smd 23 "aomori_4", modify label def district_smd 24 "chiba_1", modify label def district_smd 25 "chiba_10", modify label def district_smd 28 "chiba_13", modify label def district_smd 29 "chiba_14", modify label def district_smd 30 "chiba_2", modify label def district_smd 31 "chiba_3", modify label def district_smd 32 "chiba_4", modify label def district_smd 33 "chiba_5", modify label def district_smd 34 "chiba_6", modify label def district_smd 35 "chiba_7", modify label def district_smd 36 "chiba_8", modify label def district_smd 37 "chiba_9", modify label def district_smd 38 "ehime_1", modify label def district_smd 40 "ehime_3", modify label def district_smd 41 "ehime_4", modify label def district_smd 42 "fukui_1", modify label def district_smd 44 "fukui_3", modify label def district_smd 45 "fukuoka_1", modify label def district_smd 46 "fukuoka_10", modify label def district_smd 47 "fukuoka_11", modify label def district_smd 48 "fukuoka_2", modify label def district_smd 49 "fukuoka_3", modify label def district_smd 50 "fukuoka_4", modify label def district_smd 51 "fukuoka_5", modify label def district_smd 52 "fukuoka_6", modify label def district_smd 53 "fukuoka_7", modify label def district_smd 56 "fukushima_1", modify label values status status_label label def status_label 0 "Newcomer", modify
* party labels
************************************************** *
gen str3 party = ""
replace party = "LDP" if seito_r == 46
replace party = "DPJ" if seito_r == 42
replace party = "CDP" if seito_r == 35
************************************************** *
* opposition vote share in previous election by district
************************************************** *
gen prev_opp_voteshare = .
* Assign previous opposition vote share based on the election year
foreach year in 2000 2003 2005 2009 2012 2014 2017 2021 2024 {
* Determine opposition party (DPJ or CDP)
local opp = cond(`year' < 2017, "DPJ", "CDP")
* previous opposition vote share for the relevant district and year
bysort str_district (year): replace prev_opp_voteshare = voteshare if year == `year' & party == "`opp'"
}
************************************************** *
* Keep only LDP newcomers (status == 0)
************************************************** *
keep if seito_r == 46 & status == 0
************************************************** *
* confirm `prev_opp_voteshare`
************************************************** *
summ prev_opp_voteshare
Comment