Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Re: correcting data inconsistencies


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: correcting data inconsistencies
Date   Mon, 11 Mar 2013 13:43:26 +0000

The simple program is called Stata....

However, you have to tell it what you regard as inconsistent.

In the case, you could flag any observation that doesn't have a higher
-education- value than the previous observation in the same panel.

bysort personid (year) : gen flag1 = educ[_n+1] <= educ
by personid : gen flag2 = educ <= educ[_n-1]

list if flag1 | flag2

You could also flag panels, like that

gen problem = 0
bysort personid (year) : replace problem = sum(educ <= educ[_n-1]) if _n > 1
by personid : replace problem = problem[_N]

edit if problem

Fluency with -by:- gets you a long way.

SJ-2-1  pr0004  . . . . . . . . . . Speaking Stata:  How to move step by: step
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q1/02   SJ 2(1):86--102                                  (no commands)
        explains the use of the by varlist : construct to tackle
        a variety of problems with group structure, ranging from
        simple calculations for each of several groups to more
        advanced manipulations that use the built-in _n and _N

http://www.stata-journal.com/article.html?article=pr0004 leads to a .pdf.

Nick

On Mon, Mar 11, 2013 at 1:31 PM, David Jose <davidjosework@gmail.com> wrote:

> I would like to correct self-reported data inconsistencies in a panel
> data set. For example, if there is an education variable, which is
> reported 5 times, say as follows:
>
> year     educ
>
> 2000     12
>
> 2002     11
>
> 2004     13
>
> 2006     12
>
> 2008     11
>
> I wonder if anyone has a simple program that can be implemented to
> correct such inconsistencies. Thanks in advance.
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index