series variables in a Stata dataset. The observations are quarterly,
and all need to be rebased (for example) to the annual average value
for (say) the year 2000. The following code will find that average
value:
egen Xavg = mean(X) if tin(2000q1,2000q4)
But of course the variable Xavg here is only defined for the 4 quarters
in 2000, and is missing everywhere else. Hence, the following code
only returns values for 2000, rather than the 30 years of quarterly
observations in the sample.
gen X2000 = X / Xavg
(Yes, we're indexing to 2000 = 1 instead of 2000 = 100; this scale
factor has no subsequent effect on the analysis.)
There are a large number of series to rebase, and their starting date
varies; hence, attempting to use a [_n] construct seems not to work,
as the observation numbers that represent the year 2000 vary across the
series.
A look through the Statalist archives and with -findit- didn't turn up
any obvious hints, although it's quite possible I missed something
relevant. Thanks in advance for any assistance.