Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: error checking


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: RE: error checking
Date   Wed, 25 Sep 2002 17:23:08 -0400

> -----Original Message-----
> From: Riano, Alejandro [mailto:[email protected]] 
> Sent: Wednesday, September 25, 2002 5:02 PM
> To: [email protected]
> Subject: st: error checking
> 
> 
> I have a huge industrial survey which is a panel dataset. I 
> have the id of
> the each firm and the region in which this firm is based. I'd 
> like to check
> how many of the firms  in this dataset have errors in the 
> sense that the
> same id would be associated with a different region and/or 
> that a given firm
> would have different year of foundation. (to have an idea of 
> the % of errors
> in the database);
> I also want to know which ones are the "problematic" firms.

This should do it:

bysort firm (region): gen problem=!(region[1]==region[_N])

The logic here is that in a list sorted by region within firm, the first
and last records for a firm will be equal if and only if all records fro
the firm are in the same region.  
With the dataset sorted by region within firm, this generates a variable
called problem, which equals zero if this holds, or one if not.

Then you can -tabulate-, -list-, or do whatever with th eproblem
records.

Nick W

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index