Announcement

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

  • #16
    Originally posted by FernandoRios View Post
    Hi nguyenchihieu82vn,
    You can start with the task in a different way.
    use data,
    keep ccode
    duplicates drop ccode
    expand 11
    bysort ccode:gen year=1999+_n
    sort ccode year
    merge ccode year using data,
    This should work for the data you show.
    Best
    Worked like a charm. Thanks!

    Comment


    • #17
      Dear Nick and Clyde,

      in Stata 16.0 I have panel data of political parties in different countries over different elections. Sometimes there are multiple cabinets formed after a single election – in those cases, there are observations for each start_date for each party, but all with the same eletion_date. Sometimes a party does not gain any seats and thus has no observations for the following election, sometimes it gains again in a later election and has an observation again.

      I want to generate a variable stating if a party was in office at least for one year in a legislative term, what I aim to do by calculating the time from the current start_date until the next start_date and then using the “total()” command to sum the time by election_date. For this I first need to fill in observations for each party and start_date. In the end I will collapse the data only containing one observation for each party and election_date in that the party gained seats, which I will then “xtset” as my panel and time variable for analysis.

      My question: How can I fill in observations for all start_dates happening in a country for every party of that country?
      Neither the tsfill or fillin commands allow the “by()” option and I have yet to find another way. Using those commands fills in every start_date of every country for every party.

      Thank you!

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str14 country_name int(party_id election_date start_date)
      "Netherlands" 300 -15157 -15089
      "Netherlands" 405 -15157 -15089
      "Netherlands" 300 -13694 -13619
      "Netherlands" 405 -13694 -13619
      "Netherlands" 300 -12602 -12568
      "Netherlands" 405 -12602 -12568
      "Netherlands" 300 -12602 -12352
      "Netherlands" 405 -12602 -12352
      "Netherlands" 300 -11139 -11101
      "Netherlands" 405 -11139 -11101
      "Netherlands" 300  -9746  -9716
      "Netherlands" 405  -9746  -9716
      "Netherlands" 300  -9746  -8920
      "Netherlands" 405  -9746  -8920
      "Netherlands" 300  -8255  -8226
      "Netherlands" 405  -8255  -8226
      "Netherlands" 300  -8255  -7465
      "Netherlands" 405  -8255  -7465
      "Netherlands" 300  -8255  -7449
      "Netherlands" 405  -8255  -7449
      end
      format %tddd/nn/CCYY election_date
      format %tddd/nn/CCYY start_date
      Last edited by Anton Lang; 19 Jun 2023, 08:24.

      Comment

      Working...
      X