SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  How to match cases to subtract variables?

    Posted Mon June 07, 2021 08:43 AM

    Hello!

    I don't know if this is more a technical issue or a methodical one and I'm sorry if this forum is the wrong place for it.

    But my issue is the following. I have a data sample with election data over the course of several years. The cases are individual candidates for a single election. Now I want to calculate the margin of victory for each case.

    I think I can identify a certain election via a combination of variables like year, location, etc. However, I don't know how I would go about constructing a command, that subtracts the vote share of the candidate coming in second from the vote share of the winning candidate in a given election.

    I was thinking to maybe use a loop that activates and deactivates filters that change value (of a variable identifying an election) and for each value calculate the victory margin.

    Is there a less complicated way for that? And how would I go about creating such a variable identifying unique elections based on 2 or 3 other variable values?

    I'd be glad if someone could help me or point me to other ressources :)






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: How to match cases to subtract variables?

    Posted Mon June 07, 2021 01:04 PM

    I suppose that the number of candidates varies. Here's a sketch of a solution.

    First, use CASESTOVARS (Data > Restructure) to bring all the candidates in a given election into a single record. Then compute the maximum number of votes with the max function keeping track of which variable that was. Use the vector command for these steps so that you can refer to variables by number. You will need the COUNT subcommand to find the number of variables created this way. Then use another loop to find the max among the remaining variables.

    If you get stuck and want to send me the data and exact specification, I can provide more help (jkpeckSupport Member).






    #SPSSStatistics
    #Support
    #SupportMigration


  • 3.  RE: How to match cases to subtract variables?

    Posted Mon June 07, 2021 01:06 PM

    Thanks a lot! I will try this probably tomorrow and maybe get back to you. Thanks for the offer!






    #SPSSStatistics
    #Support
    #SupportMigration