Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Electoral Data and Margin of Victory

    Dear All,

    I am trying to calculate the margin of victory in my election data set. I have election data for two years: 2016 and 2021. I aim to look at close elections in an RDD study. However, the codes that I am using and have tried following a statalist thread do not seem to work for me. Any help would be highly appreciated. An example of the code using dataex.

    Legislative is the county. Party variable represents the political party and position refers to the position of the candidate in the election. Ideally, I would want to know the margin of victory of BJP and AITC.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str22 legislative int year str52 party long votes byte position int constituency_no
    "ALIPURDUARS"     2016 "BJP"         20098 3  12
    "ALIPURDUARS"     2016 "INC"         77737 2  12
    "ALIPURDUARS"     2016 "AITC"        89695 1  12
    "ALIPURDUARS"     2021 "INC"         15651 3  12
    "ALIPURDUARS"     2021 "AITC"        91326 2  12
    "ALIPURDUARS"     2021 "BJP"        107333 1  12
    "AMDANGA"         2016 "BJP"         15691 3 102
    "AMDANGA"         2016 "CPM"         73228 2 102
    "AMDANGA"         2016 "AITC"        96193 1 102
    "AMDANGA"         2021 "RSSCMJP"     50905 3 102
    "AMDANGA"         2021 "BJP"         63455 2 102
    "AMDANGA"         2021 "AITC"        88935 1 102
    "AMTA"            2016 "BJP"         11045 3 181
    "AMTA"            2016 "AITC"        84645 2 181
    "AMTA"            2016 "INC"         89149 1 181
    "AMTA"            2021 "INC"         25109 3 181
    "AMTA"            2021 "BJP"         76240 2 181
    "AMTA"            2021 "AITC"       102445 1 181
    "ARAMBAGH"        2016 "BJP"         17261 3 200
    "ARAMBAGH"        2016 "CPM"         71122 2 200
    "ARAMBAGH"        2016 "AITC"       107579 1 200
    "ARAMBAGH"        2021 "CPM"         14965 3 200
    "ARAMBAGH"        2021 "AITC"        95936 2 200
    "ARAMBAGH"        2021 "BJP"        103108 1 200
    "ASANSOL DAKSHIN" 2016 "BJP"         49199 3 280
    "ASANSOL DAKSHIN" 2016 "CPM"         57232 2 280
    "ASANSOL DAKSHIN" 2016 "AITC"        71515 1 280
    "ASANSOL DAKSHIN" 2021 "CPM"         15972 3 280
    "ASANSOL DAKSHIN" 2021 "AITC"        83394 2 280
    "ASANSOL DAKSHIN" 2021 "BJP"         87881 1 280
    "ASANSOL UTTAR"   2016 "INC"         31892 3 281
    "ASANSOL UTTAR"   2016 "BJP"         60818 2 281
    "ASANSOL UTTAR"   2016 "AITC"        84715 1 281
    "ASANSOL UTTAR"   2021 "RSSCMJP"      4471 3 281
    "ASANSOL UTTAR"   2021 "BJP"         79821 2 281
    "ASANSOL UTTAR"   2021 "AITC"       100931 1 281
    end
    The codes that I have tried:

    Code:
    *Code 1
    bys legislative year (votes): g victory_margin = ///
        100*(votes[_N]-votes[_N-1])/votes[_N-1]
     
    *Code 2   
    by legislative year: g margin_of_victory = 100*(votes - votes[_n-1])/votes[_n-1] if _n > 1 & party != party[_n-1]
    The output that I have received:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str22 legislative int year str52 party long votes byte position int constituency_no float(victory_margin margin_of_victory)
    "ALIPURDUARS"     2016 "BJP"         20098 3  12 15.382636         .
    "ALIPURDUARS"     2016 "INC"         77737 2  12 15.382636 286.78973
    "ALIPURDUARS"     2016 "AITC"        89695 1  12 15.382636 15.382636
    "ALIPURDUARS"     2021 "INC"         15651 3  12 17.527319         .
    "ALIPURDUARS"     2021 "AITC"        91326 2  12 17.527319  483.5154
    "ALIPURDUARS"     2021 "BJP"        107333 1  12 17.527319 17.527319
    "AMDANGA"         2016 "BJP"         15691 3 102 31.360954         .
    "AMDANGA"         2016 "CPM"         73228 2 102 31.360954  366.6879
    "AMDANGA"         2016 "AITC"        96193 1 102 31.360954 31.360954
    "AMDANGA"         2021 "RSSCMJP"     50905 3 102  40.15444         .
    "AMDANGA"         2021 "BJP"         63455 2 102  40.15444 24.653767
    "AMDANGA"         2021 "AITC"        88935 1 102  40.15444  40.15444
    "AMTA"            2016 "BJP"         11045 3 181  5.321047         .
    "AMTA"            2016 "AITC"        84645 2 181  5.321047  666.3649
    "AMTA"            2016 "INC"         89149 1 181  5.321047  5.321047
    "AMTA"            2021 "INC"         25109 3 181  34.37172         .
    "AMTA"            2021 "BJP"         76240 2 181  34.37172 203.63614
    "AMTA"            2021 "AITC"       102445 1 181  34.37172  34.37172
    "ARAMBAGH"        2016 "BJP"         17261 3 200  51.25981         .
    "ARAMBAGH"        2016 "CPM"         71122 2 200  51.25981  312.0387
    "ARAMBAGH"        2016 "AITC"       107579 1 200  51.25981  51.25981
    "ARAMBAGH"        2021 "CPM"         14965 3 200  7.475817         .
    "ARAMBAGH"        2021 "AITC"        95936 2 200  7.475817 541.06915
    "ARAMBAGH"        2021 "BJP"        103108 1 200  7.475817  7.475817
    "ASANSOL DAKSHIN" 2016 "BJP"         49199 3 280  24.95632         .
    "ASANSOL DAKSHIN" 2016 "CPM"         57232 2 280  24.95632 16.327568
    "ASANSOL DAKSHIN" 2016 "AITC"        71515 1 280  24.95632  24.95632
    "ASANSOL DAKSHIN" 2021 "CPM"         15972 3 280  5.380483         .
    "ASANSOL DAKSHIN" 2021 "AITC"        83394 2 280  5.380483  422.1262
    "ASANSOL DAKSHIN" 2021 "BJP"         87881 1 280  5.380483  5.380483
    "ASANSOL UTTAR"   2016 "INC"         31892 3 281  39.29264         .
    "ASANSOL UTTAR"   2016 "BJP"         60818 2 281  39.29264  90.69986
    "ASANSOL UTTAR"   2016 "AITC"        84715 1 281  39.29264  39.29264
    "ASANSOL UTTAR"   2021 "RSSCMJP"      4471 3 281 26.446674         .
    "ASANSOL UTTAR"   2021 "BJP"         79821 2 281 26.446674 1685.3053
    "ASANSOL UTTAR"   2021 "AITC"       100931 1 281 26.446674 26.446674
    end
    The output does not seem correct.

  • #2
    The output looks correct to me, or at least it corresponds with what you asked Stata to do. So could you tell us what you think is wrong about it?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment

    Working...
    X