Announcement

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

  • Generating marginality(difference) variable

    Hi,

    I'm trying to create a variable that contains information on marginality between political parties. I want to assign each party a value with the difference between the vote share of the party and the vote share of the next party below it.

    As I have 145 observations and assigning each party individually its value would be very time consuming, I was wondering if anybody could think of a better solution? I'm sure it can't be too complicated as this is a simple subtraction.

    Here is an example of how I started to assign some values per hand (e.g. NOR "Soc social democrats" gets the value 19.7 in 1997 (35-15.30)).
    Code:
    ***Marginality***
    gsort year dataset_country_id -size_p
    
    cap drop marg
    gen marg=.
    
    replace marg=19.7 if party==12320 & year==1997
    replace marg=5.78 if party==41320 & year==1998
    replace marg=11.92 if party==13320 & year==1998
    replace marg=4.29 if party==22320 & year==1998
    replace marg=13.49 if party==11320 & year==1998
    replace marg=13.96 if party==15620 & year==1999
    replace marg=2.17 if party==13420 & year==2001



    I would be very thankful for any advise. Below is an example of my dataset (the first 20 observations) in dataex.

    Best,
    Johanna




    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int manifesto_country_id float edate long(date party) str183 partyname str29 partyabbrev int parfam double(size_p rile) float year str3 dataset_country_id double manifesto_party_id str5 dataset_id float(self_rile new_rile party_voter inc number_p)
    12 13773 199709 12320 "Norwegian Labour Party"                            "DnA"       30     35 -18.112 1997 "NOR" 12320 "CSES1"     4.305 3.1219435 2.3996224 1  7
    12 13773 199709 12951 "Progress Party"                                    "FrP"       95   15.3  23.478 1997 "NOR" 12951 "CSES1"  7.031915  7.786801  1.569853 0  7
    12 13773 199709 12620 "Conservative Party"                                "H"         60  14.34   3.692 1997 "NOR" 12620 "CSES1"  7.425373  5.567544  4.451527 0  7
    12 13773 199709 12520 "Christian People’s Party"                        "KrF"       50  13.66  -4.549 1997 "NOR" 12520 "CSES1"  5.453846 4.6432095 1.6571316 1  7
    12 13773 199709 12810 "Centre Party"                                      "Sp"        80   7.93 -10.553 1997 "NOR" 12810 "CSES1"  4.601504  3.969783  1.399071 1  7
    12 13773 199709 12221 "Socialist Left Party"                              "SV"        20   6.01 -25.363 1997 "NOR" 12221 "CSES1"  2.760684   2.30865 1.2043345 0  7
    12 13773 199709 12420 "Liberal Party"                                     "V"         40   4.45  -7.897 1997 "NOR" 12420 "CSES1"  4.702381 4.2676883 1.1889579 1  7
    41 14149 199809 41320 "Social Democratic Party of Germany"                "SPD"       30 40.929  -1.603 1998 "DEU" 41320 "CSES1"  3.704309  4.973642  2.611206 1  6
    41 14149 199809 41521 "Christian Democratic Union/Christian Social Union" "CDU/CSU"   50 35.145  24.868 1998 "DEU" 41521 "CSES1"  5.243781  7.942707  8.284202 0  6
    41 14149 199809 41521 "Christian Democratic Union/Christian Social Union" "CDU/CSU"   50 35.145  24.868 1998 "DEU" 41521 "CSES1"  5.571429  7.942707  6.622961 0  6
    41 14149 199809 41113 "Alliance‘90/Greens"                              "90/Greens" 10  6.696 -16.256 1998 "DEU" 41113 "CSES1"  2.952756  3.330118  1.142402 1  6
    41 14149 199809 41420 "Free Democratic Party"                             "FDP"       40  6.248  14.704 1998 "DEU" 41420 "CSES1"  4.847059  6.802683  4.824466 0  6
    41 14149 199809 41221 "Party of Democratic Socialism"                     "PDS"       20  5.101 -26.816 1998 "DEU" 41221 "CSES1"  2.186813 2.1456773 1.0016922 0  6
    13 13949 199803 13320 "Social Democratic Party"                           "SD"        30  35.93  -1.042 1998 "DNK" 13320 "CSES1" 4.4651165  5.036565 1.3265537 1 10
    13 13949 199803 13420 "Liberals"                                          "V"         40  24.01  28.571 1998 "DNK" 13420 "CSES1"     7.125  8.358047  2.520404 0 10
    13 13949 199803 13620 "Conservative People’s Party"                     "KF"        60   8.92  18.672 1998 "DNK" 13620 "CSES1"  7.244792  7.247746 1.0000087 0 10
    13 13949 199803 13230 "Socialist People’s Party"                        "SF"        20   7.56  -39.59 1998 "DNK" 13230 "CSES1"  2.993631  .7129077  6.201697 0 10
    13 13949 199803 13720 "Danish People’s Party"                           "DF"        70   7.41   9.722 1998 "DNK" 13720 "CSES1"  7.170732  6.243887  1.859041 0 10
    13 13949 199803 13330 "Centre Democrats"                                  "CD"        30   4.31 -14.019 1998 "DNK" 13330 "CSES1"  5.876543 3.5810266  6.269396 0 10
    13 13949 199803 13410 "Danish Social-Liberal Party"                       "RV"        40   3.85  -5.455 1998 "DNK" 13410 "CSES1"  4.634146   4.54159 1.0085666 1 10
    end
    format %td edate
    format %ty year
    label values manifesto_country_id countries
    label def countries 12 "norway", modify
    label def countries 13 "denmark", modify
    label def countries 41 "germany", modify
    label values party party
    label def party 12221 "nor: Socialist Left Party", modify
    label def party 12320 "nor: Norwegian Labour Party", modify
    label def party 12420 "nor: Liberal Party", modify
    label def party 12520 "nor: Christian People’s Party", modify
    label def party 12620 "nor: Conservative Party", modify
    label def party 12810 "nor: Centre Party", modify
    label def party 12951 "nor: Progress Party", modify
    label def party 13230 "dnk: Socialist People’s Party", modify
    label def party 13320 "dnk: Social Democratic Party", modify
    label def party 13330 "dnk: Centre Democrats", modify
    label def party 13410 "dnk: Danish Social-Liberal Party", modify
    label def party 13420 "dnk: Liberals", modify
    label def party 13620 "dnk: Conservative People’s Party", modify
    label def party 13720 "dnk: Danish People’s Party", modify
    label def party 41113 "deu: Alliance‘90/Greens", modify
    label def party 41221 "deu: Party of Democratic Socialism", modify
    label def party 41320 "deu: Social Democratic Party of Germany", modify
    label def party 41420 "deu: Free Democratic Party", modify
    label def party 41521 "deu: Christian Democratic Union/Christian Social Union", modify
    label values parfam parfam
    label def parfam 10 "eco ecologist", modify
    label def parfam 20 "com communist", modify
    label def parfam 30 "soc social democratic", modify
    label def parfam 40 "lib liberal", modify
    label def parfam 50 "chr christian democrat", modify
    label def parfam 60 "con conservative", modify
    label def parfam 70 "nat nationalist", modify
    label def parfam 80 "agr agrarian", modify
    label def parfam 95 "sip special issue", modify
    label values inc inc
    label def inc 0 "No Incubency", modify
    label def inc 1 "Incubency", modify
    Last edited by Johanna Bjarnadottir; 24 Sep 2018, 07:40.

  • #2
    You'll notice that the screenshot that you posted is not readable here. Please search on and read about "screenshots, "code delimiters," and "dataex" in the FAQ (accessible through at the top of the page in the forum.) You'll have a much better chance of getting a helpful answer here if follow the advice regarding those items here.

    Comment


    • #3
      Mike Lacy Thank you for your advise! I see now that I should have read the FAQ before my post.

      Comment


      • #4
        Although your -dataex- example did not contain situations with multiple years for a given country, I'm presuming that might occur in your actual data, and so I'm including consideration of year. I believe the following will do what you want:
        Code:
        bysort year manifesto_country_id (size_p): gen marg = size_p- size_p[_n-1]
        Next time: Answering your question would have been easier if you had told us that the vote share variable is size_p. I needed to scan through many columns of your data to find some of the values you mentioned and then infer which variable had this information.

        Comment


        • #5
          Mike Lacy Thank you so much for your help!
          The coded was exactly what I needed. I'll explore the bysort command in more depth when I have a problem of this sort again.
          Also, thank you for your tips regarding the statalist in general. As I am new here I'll keep them in mind for next time.

          Comment

          Working...
          X