I am working with the MARPOR dataset using STATA15.1.
In the dataset there are a number of observations (parties) per country per election date (there are in some cases numerous elections in a given year). I wish to use the count of elections within a certain country as opposed to the election date itself to structure the panel of my data. i.e. instead of using the election date, I wish to create a running count of elections: for example the first election to take place in Spain in the timeframe of my data would have value "1" and the value for each election would increase by one.
Below is an example of some of the coding attempts I have tried. I hope to not have to count the elections per country manually.
The rank command gives me values for ecount that are unclear. The value for count relying on _n just give me the total number of observations per country.
In the dataset there are a number of observations (parties) per country per election date (there are in some cases numerous elections in a given year). I wish to use the count of elections within a certain country as opposed to the election date itself to structure the panel of my data. i.e. instead of using the election date, I wish to create a running count of elections: for example the first election to take place in Spain in the timeframe of my data would have value "1" and the value for each election would increase by one.
Below is an example of some of the coding attempts I have tried. I hope to not have to count the elections per country manually.
Code:
egen ecount=rank(edate), by(country)
Code:
sort country year egen id=group(country) by id date: gen ecount=_n, by(country)
Comment