Note that use of the -egen- function -nvals()-
depends on prior installation of the -egenmore-
package from SSC.
Nick
[email protected]
Michael Blasnik
There are a couple of approaches you could take, but I think
using egen
nvals is the best bet.
sort subarea
by subarea: egen nyears=nvals(year)
keep if nyears>=13
sort subarea
by subarea: egen firstfive=nvals(year) if year<=5
by subarea: egen lastfive=nvals(year) if year>21
* fill out missing values within subarea
bysort subarea (firstfive): replace firstfive=firstfive[1]
bysort subarea (lastfive): replace lastfive=lastfive[1]
keep if firstfive>=2 & lastfive>=2
drop nyears firstfive lastfive
Jennifer Devine
> Can someone please set me in the right direction for coding
a program to
> count and eliminate data if it doesn't meet a certain criteria?
>
> I have survey data taken over 26 years and the survey area
is divided
> into subareas. I want to only include a subarea if data was
collected 13
> years out of the 26 and data must have been collected 2
years of the first
> 5 years and 2 years of the last 5 years. If the subarea
does not meet that
> criteria, I want Stata to drop that subarea from the
analysis. At the
> moment, I'm having to look at everything individually and
it takes several
> days to eliminate subareas.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/