Announcement

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

  • Number of splitvoters from two variables

    I need to know the number of split voters in Denmark - those who did not vote for the same party at the general and the local election.

    An example:

    A person votes for Socialdemokratiet at the general and the local election = not a split voter
    A person votes for Socialdemokratiet at the general election and for Venstre at the local election = split voter


    Variable 1: Which party did you vote for at the generel election

    (Danish parties below)

    1. Socialdemokratiet
    2. Det Radikale Venstre
    3. Det Konservative Folkeparti
    4. SF - Socialistisk Folkeparti
    5. Kristendemokraterne
    6. Liberal Alliance
    7. Dansk Folkeparti
    8. Venstre
    9. Enhedslisten

    Variable 2: Which party did you vote for at the local election

    (Danish parties below)

    1. Socialdemokratiet
    2. Det Radikale Venstre
    3. Det Konservative Folkeparti
    4. SF - Socialistisk Folkeparti
    5. Kristendemokraterne
    6. Liberal Alliance
    7. Dansk Folkeparti
    8. Venstre
    9. Enhedslisten


    How can this be done in Stata? Should i gen. a new variable to make this possible?


    I hope someone can help me out here.. :-)


    Best regards

    Mikkel


  • #2
    MIkkel:
    the following toy-example might be helpful:
    Code:
    . set obs 3
    number of observations (_N) was 0, now 3
    
    . g id=_n
    
    . gen RF_home_suporter=1 in 1/2 /*RF=Roger Federer*/
    
    . replace RF_home_suporter=0 if RF_home_suporter==.
    
    . gen RF_abroad_suporter=1 if _n==1 | _n==3
    
    . replace RF_abroad_suporter=0 if RF_abroad_suporter==.
    
    . gen RF_split_supporter=1 if RF_home_suporter!=RF_abroad_suporter
    
    . replace RF_split_supporter=0 if RF_home_suporter==RF_abroad_suporter
    
    . label define RF_split_supporter 0 "Non-split supporter" 1 "Split supporter"
    
    . label val RF_split_supporter RF_split_supporter
    
    . list
    
         +------------------------------------------------+
         | id   RF_hom~r   RF_abr~r    RF_split_supporter |
         |------------------------------------------------|
      1. |  1          1          1   Non-split supporter |
      2. |  2          1          0       Split supporter |
      3. |  3          0          1       Split supporter |
         +------------------------------------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      why not just,
      Code:
      gen splitvoter = variable_1 != variable_2
      ?

      Comment


      • #4
        That easy? Thanks a lot!

        Im in doubt about the interpretation of the new gen. var. named splitvoter.

        Can you explain the code maybe?


        tab. splitvoter
        0 n: 1596
        1 n: 2933
        Total n: 4528

        Best regards

        Mikkel

        Comment


        • #5
          Mikkel:
          do you have missing values in var_1 and/or var_2?
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Mikkel, combining Øyvind's code and Carlo's reminder, you may run the code:

            Code:
            gen splitvoter = variable_1 != variable_2 if !mi(variable_1) & !mi(variable_2)
            Splitvoter = 1 for split voters, = 0 for non-split voters.

            Comment


            • #7
              Hi again

              I have no missings.

              Before I would type [keep if var_1==1 & var_2==2].
              That will give me the number of splitvoteres who vote for Socialdemokratiet in the general election and Radikale Venstre in the local election (n=43).
              I will have to do it for every singe possible splitvoting scenaria and count the numbers and in the end sum up and generate the variable...

              Above must be the hardest way..

              Comment


              • #8
                Fei Wang, thanks!

                Can you explain that in words for me to understand the code?

                gen splitvoter = variable_1 != variable_2 if !mi(variable_1) & !mi(variable_2) Best regards Mikkel



                Comment


                • #9
                  Originally posted by Mikkel Valentin View Post
                  Fei Wang, thanks!

                  Can you explain that in words for me to understand the code?

                  gen splitvoter = variable_1 != variable_2 if !mi(variable_1) & !mi(variable_2) Best regards Mikkel
                  The problem with my code is that it identifies people who only vote at one election as a split voter.

                  The code
                  Code:
                  gen splitvoter = variable_1 != variable_2
                  says that a split voter is any voter for which variable_1 does not equal variable_2.

                  While,
                  Code:
                  gen splitvoter = variable_1 != variable_2 if !mi(variable_1) & !mi(variable_2)
                  says that a split voter is any voter for which variable_1 does not equal variable_2, and who voted at both elections.

                  Does that make sense?

                  Comment


                  • #10
                    Ah perfect! Thanks a lot - it makes sense :-)

                    Have a nice weekend All!

                    Best regards

                    Mikkel

                    Comment

                    Working...
                    X