Hello all,
I would like to calculate the product of probabilities of annual coup risk based on the monthly coup risk of the following dataset.
ccode country leader year month couprisk couprisk_annual leader_dupli
2 "USA" "Ford" 1975 1 .0003171 NA 0
2 "USA" "Ford" 1975 2 .0003072 NA 0
2 "USA" "Ford" 1975 3 .0003242 NA 0
2 "USA" "Ford" 1975 4 .0003552 NA 0
2 "USA" "Ford" 1975 5 .0003206 NA 0
2 "USA" "Ford" 1975 6 .0003265 NA 0
2 "USA" "Ford" 1975 7 .0003095 NA 0
2 "USA" "Ford" 1975 8 .0003262 NA 0
2 "USA" "Ford" 1975 9 .0003025 NA 0
2 "USA" "Ford" 1975 10 .0003145 NA 0
2 "USA" "Ford" 1975 11 .0003275 NA 0
2 "USA" "Ford" 1975 12 .0003267 NA 0
2 "USA" "Ford" 1976 1 .0002369 NA 0
2 "USA" "Ford" 1976 2 .0002145 NA 0
2 "USA" "Ford" 1976 3 .0014412 NA 0
2 "USA" "Ford" 1976 4 .0012788 NA 0
2 "USA" "Ford" 1976 5 .0002297 NA 0
2 "USA" "Ford" 1976 6 .0002309 NA 0
2 "USA" "Ford" 1976 7 .0002361 NA 0
2 "USA" "Ford" 1976 8 .0014302 NA 0
2 "USA" "Ford" 1976 9 .0002547 NA 0
2 "USA" "Ford" 1976 10 .0002834 NA 0
2 "USA" "Ford" 1976 11 .0005047 NA 0
2 "USA" "Ford" 1976 12 .0002395 NA 0
2 "USA" "Ford" 1977 1 .0001886 NA 1
2 "USA" "Carter" 1977 1 .0002034 NA 1
2 "USA" "Carter" 1977 2 .0002668 NA 0
2 "USA" "Carter" 1977 3 .0002384 NA 0
2 "USA" "Carter" 1977 4 .0002643 NA 0
2 "USA" "Carter" 1977 5 .000266 NA 0
2 "USA" "Carter" 1977 6 .0002311 NA 0
2 "USA" "Carter" 1977 7 .0002445 NA 0
2 "USA" "Carter" 1977 8 .0002389 NA 0
2 "USA" "Carter" 1977 9 .0002378 NA 0
2 "USA" "Carter" 1977 10 .000242 NA 0
2 "USA" "Carter" 1977 11 .000272 NA 0
2 "USA" "Carter" 1977 12 .0002942 NA 0
For example, a formulation of the annual coup risk probability would be "1-[(1-couprisk_Jan)*(1-couprisk_Feb)*(1-couprisk_Mar)*...*(1-couprisk_Dec)]".
Stata code that I thought would be:
bysort ccode : replace couprisk_annual = 1- (1-couprisk[_n]) * (1-couprisk[_n+1]) * ///
(1-couprisk[_n+2]) * (1-couprisk[_n+3]) * (1-couprisk[_n+4]) * (1-couprisk[_n+5]) * ///
(1-couprisk[_n+6]) * (1-couprisk[_n+7]) * (1-couprisk[_n+8]) * (1-couprisk[_n+9]) * (1-couprisk[_n+10]) * (1-couprisk[_n+11]) //
Accordingly, I expect to get the annual coup probability in the first month of each year (January) for the years 1975 and 1976. After that, I can replace this probability for the remaining months between Feb and Dec.
The problem is that Stata code will not be applicable to the cases in which multiple leader months exist. As you can see above, in 1977, there exist two observations per month since there was a leader change in January 1977.
A bigger issue is that my dataset has a total of 66,846 low, including over 200 countries, and there are many countries where more than two observations per month exist within a year.
Alternatively, I thought about using "collapse" command as follows.
collapse (mean) couprisk , by(country year)
However, the mean of coup risk is not what I want to get. What I want to calculate is the product of probability following my formula "1-[(1-couprisk_Jan)*(1-couprisk_Feb)*(1-couprisk_Mar)*...*(1-couprisk_Dec)]".
How can I tell Stata to calculate the yearly coup risk probability of each state following my formula given that multiple observations per month exist?
Any suggestions and comments will be appreciated.
Thank you
Related Posts with Aggregating monthly time series data into a yearly time series, and calculating the product of probability
Problem with a parametic survival analysisHi! Sorry, this will probably end long, but I really need som help. I am doing a reliability analy…
teffects loops, inconsistent covariate coverage, and perfect predictorsHello, I am stumped on a coding problem. I am measuring the treatment effect on each of multiple out…
Bootstrapping in dominance analysisDear Stata experts. using Code: webuse auto // Binary outcome dominance analysis with factor var…
Data panelHello Mr. what is the function, characteristics,its importance, its Benefits of the vce(custer citie…
Omitted variable due to CollinearityHi guys, I am trying to find which coefficient beta 1 or 2 has a greater effect on child mortality.…
Subscribe to:
Post Comments (Atom)
0 Response to Aggregating monthly time series data into a yearly time series, and calculating the product of probability
Post a Comment