I've been calculating changes in GDP in countries for adjacent quarters (gen ch_gdp =gdp_quart-gdp_quart[_n-1]) and between elections. Elections are identified in the dataset by a variable in a column set at one, and in most countries are held at irregular intervals. I got the right answers by dropping non-election quarters and simply subtracting to get the change, then merging the reduced dataset back with the full dataset. However, I wondered if there was a way of subtracting current GDP from GDP in the last quarter in which an election was held. To do this _n would have to be set for each country at the interval since the last election.
Suggestions are welcome. Thanks, Matthew Gibbons
clear
input float improv_date str9 name byte country_code double gdp_new float election
110 "Australia" 1 26790.047 1
111 "Australia" 1 27216.911 .
112 "Australia" 1 27221.578 .
113 "Australia" 1 27136.507 .
114 "Australia" 1 27226.016 .
115 "Australia" 1 27521.458 .
116 "Australia" 1 27692.138 .
117 "Australia" 1 28178.127 .
118 "Australia" 1 28314.128 .
119 "Australia" 1 28132.636 .
120 "Australia" 1 28251.493 1
121 "Australia" 1 28184.019 .
122 "Australia" 1 27932.673 .
123 "Australia" 1 28014.252 .
124 "Australia" 1 27541.83 .
125 "Australia" 1 27425.182 .
126 "Australia" 1 27458.474 .
127 "Australia" 1 27411.614 .
128 "Australia" 1 27524.306 .
129 "Australia" 1 27653.573 .
130 "Australia" 1 27863.971 .
131 "Australia" 1 28384.523 .
132 "Australia" 1 28500.421 1
end
Related Posts with Calculating changes in a variable over irregular intervals when a condition is met in grouped data
How to take a random sample of panel data and keep all person-year-observations for a particular IDI try to take a random sample from a huge unbalanced panel dataset. For the MWE data, I would like t…
Mediation analysis (bias-corrected bootstrapping): Using panel survey data with fixed effects (sem/gsem/xtdpdml command)Hello, I am new to the Stata forum (let me know if I have not correctly followed the forum's rules)…
Editing graphHi, I need to edit a graph that starts from 0 to start from 10. I know how to change the x axis ran…
How to add scatter plot to xtline and modify its colours accordinglyHi, I'm trying to add orginial data to xtline. Sometimes a unit exhibits a constant variable over se…
Combining the values of different categories into ONE with a repeated IDI have a variable (foodgr) which is divided into 4 categories (1,2,3,4). I have another variable, v…
Subscribe to:
Post Comments (Atom)
0 Response to Calculating changes in a variable over irregular intervals when a condition is met in grouped data
Post a Comment