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]

st: checking data using assert


From   Raoul Reulen <r.c.reulen@bham.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: checking data using assert
Date   Wed, 29 May 2013 03:00:39 +0100

Hi All,

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

Many thanks for help! Appreciated as usual!

All the best

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