Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: checking data using assert
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: checking data using assert
Date
Wed, 29 May 2013 06:43:26 +0100
This feeds my prejudice that -count- is often overlooked. See
SJ-7-1 pr0029 . . . . . . . . . . . . . . . Speaking Stata: Making it count
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q1/07 SJ 7(1):117--130 (no commands)
discusses count used with a loop over observations
or variables
http://www.stata-journal.com/sjpdf.html?articlenum=pr0029 for freely
available .pdf
I would make the actions conditional on finding problems (positive
count). There is no need to use -assert- or create a new variable.
qui count if dod < dob
if r(N) > 0 {
di _new as err "date of death before birth date':"
list id dob dod if dod < dob, noobs N
}
Nick
[email protected]
On 29 May 2013 03:00, Raoul Reulen <[email protected]> wrote:
> I am currently running several do-files in order to check data. I would like Stata to check whether a certain statement is true, e.g. date of birth (dob) < date of death (dod). If it is not true I want it to display a message saying what the problem is and display the ID numbers for those records were the statement was not true. Lastly, I want to list several variables (e,g. id, dob, dox) to inspect the actual problem.
>
> I have done the following, but wondered if there are easier/more efficient ways of doing it?
>
> ******************************
> .gen byte tag = dod < dob
> .qui: levelsof id if tag==1
> .cap: assert tag==0
> .if _rc di _new as err "date of death before birth date; see id: " as text "`r(levels)'"
> .list id dob dod if tag==1 , noobs N
> .drop tag
> ******************************
*
* 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/