Dear all,
how can I fill in observations for every combination of time values (in this case the variable “start_date”) and panel values (in this case the variable “party_id”) but only of their respective country?
Neither the tsfill or fillin commands allow the “by(x)” option and I have yet to find another way. Using those commands fills in every start_date of every country for every party_id and blows up my dataset from previously 4,710 observations to 10,298,712.
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_id, but all with the same election_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 “egen x = total(y)” command to sum the time by election_date. For this I first need to fill in observations for each party_id and start_date. In the end I will collapse the data only containing one observation for each party_id and election_date in that the party gained seats, which I will then “xtset” as my panel and time variable for analysis.
I previously posted this question in another thread which I found fitting, but I am sorry to only now realise, that it should be in a new thread.
Here is the link to the old post: https://www.statalist.org/forums/for...nel-data/page2
Hope someone can help here and thanks in advance!
how can I fill in observations for every combination of time values (in this case the variable “start_date”) and panel values (in this case the variable “party_id”) but only of their respective country?
Neither the tsfill or fillin commands allow the “by(x)” option and I have yet to find another way. Using those commands fills in every start_date of every country for every party_id and blows up my dataset from previously 4,710 observations to 10,298,712.
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_id, but all with the same election_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 “egen x = total(y)” command to sum the time by election_date. For this I first need to fill in observations for each party_id and start_date. In the end I will collapse the data only containing one observation for each party_id and election_date in that the party gained seats, which I will then “xtset” as my panel and time variable for analysis.
I previously posted this question in another thread which I found fitting, but I am sorry to only now realise, that it should be in a new thread.
Here is the link to the old post: https://www.statalist.org/forums/for...nel-data/page2
Hope someone can help here and thanks in advance!
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
Comment