Announcement

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

  • Modifying a variable conditional on the value of another variable

    Hi everyone,

    This is a basic question, but I have not come up with an answer. I am calculating the majoritarian party in a council or in other words when variable "percent_majority_party">0.51.


    Each row below corresponds to one elected official for a particular province and municipality. Variable "percent_majority_Party" represents the percentage of council members per "party" in each province and municipality. The main challenge: in case of a split or no majority ("percent_majority_Party" is <0.51), the party of the "VICE-MAYOR" should help determine the majoritarian party. In the example below: there are three parties in the council and no majority ("percent_majority_Party" is <0.51), but "VICE-MAYOR" would give the majority to the party. "NUP."

    This is how I would solve this issue. Still, I don't know how to code it (I would appreciate your help in the following): I want to compare per province municipality if the VICE-MAYOR party (party1) is equal to the "COUNCILOR's" party; this binary variable would help me identify which party is the majority based on VICE-MAYOR's party in case of splits. With this vector of zeroes and ones, I would like to know how I can replace the "percent_majority_party" of the majoritarian party by 0.51 in the cases where the councilors party and vice-mayor party are coincident. In my example, how could I replace .3 of "NUP" with 0.51.


    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str25 province str47 municipality str14 position str30 party1 str11 Party_vice_mayor float percent_majority_party str11 Party_cc_4
    "QUEZON" "Agdangan" "COUNCILOR" "INDEPENDENT" "" .3 ""
    "QUEZON" "Agdangan" "COUNCILOR" "UNA" "" .3 ""
    "QUEZON" "Agdangan" "COUNCILOR" "NUP" "" .3 ""
    "QUEZON" "Agdangan" "VICE-MAYOR" "NUP" "NUP" .3 "NUP"

    I would appreciate your help,

    David
    Last edited by David Castro Pena; 23 May 2022, 23:38.

  • #2
    Code:
    bysort province municipality (Party_vice_mayor): replace Party_vice_mayor = Party_vice_mayor[_N] if mi(Party_vice_mayor)
    replace percent_majority_party = 0.51 if party1 == Party_vice_mayor
    I recommend an indicator,
    Code:
    gen majority = party1 == Party_vice_mayor

    Comment


    • #3
      Thanks a lot, Øyvind--it worked!

      Comment

      Working...
      X