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
Why is R2 greater than 1.0 in this PCSE analysis?I encountered a perplexing set of results after running xtpcse. R-squared = 1.1892. Any ideas why th…
How to count a purchase date of medicines?Hello! This is Babar, quite new here in this forum and here is my first question. " I have a long d…
Variable with negative valuesHey, I'm stuck on a simple thing and would really need some help. I have a non-numeric variable ran…
Generating variable and replacing the outlier as missing based on grouping and conditionDear All, I am working with firm level data. I want to generate a variable lsales = ln(sales) and wa…
Complicate box plotHii guys, I have a database made as follows: Code: * Example generated by -dataex-. To install: s…
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