[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: collapse if at least X or more obs. per group are non-missing
I'd like to convert a panel data set with annual country obs to one of
decadal country averages, excluding those decadal averages for which 5 or
more observations per country are missing within a decade.
My first idea was to use a two step procedure along the lines of:
collapse (mean) GDP (count) GDP , by(country decade)
this should give me a) the decadal averages I want and b) the number of
non-missing obs used to compute each of these decadal averages.
2. replace mean_GDP=. if count_GDP<5 (or whatever STATA will call these vars
saving the means & counting the non-missing obs)
this should set to missing those decadal averages for which 5 or more
observations per country were missing within each decade.
However, trying this I get the following error message:
. collapse (count) GDP (mean) GDP, by(sftgcode decade)
GDP = (count) GDP
GDP = (mean) GDP
Does this mean that I cannot get means and counts for the same variable at
the same time when using collapse? Moreover, is there any way to directly
aggregate annual obs to decadal country averages while omitting those
averages for which a pre-specified number of obs. is missing per country?
I wasn't able to find any solution to this on the archives, although I
assume it's a rather common problem. Thank you very much for your help.
* For searches and help try: