Quantcast

skip functions containing missing variables?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

skip functions containing missing variables?

Michael Costello
Dear awesome Statalisters,

I have about 25 databases with similar (but not exactly the same)
variable lists.  I want to "clean" them up by adjusting labels,
formats, etc.  Is there a way to have stata simply skip an absent
variable so taht I can run the same .do file on every database?  For
example:

one.dta varlist: gender age date grade speed
two.dta varlist: gender date grade speed

Since age is missing from the second database if I run a script saying
"label variable age "How old is the student?" " stata would stop
running because of an error.  Or, if I tried to change the order of
the (present) variables, it would have an error when it came to the
missing age variable.

So is there a way I can avoid this error?  Is there some prefix that
says: Do only when variables are present?

-Michael
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: skip functions containing missing variables?

nshephard
Administrator
On Tue, Nov 16, 2010 at 11:51 AM, Michael Costello
<[hidden email]> wrote:
>
> So is there a way I can avoid this error?  Is there some prefix that
> says: Do only when variables are present?

-man capture- is likely what you're looking for here.

Neil


--
"Our civilization would be pitifully immature without the intellectual
revolution led by Darwin" - Motoo Kimura, The Neutral Theory of
Molecular Evolution

Email - [hidden email]
Website - http://kimura-no-ip.org/
Photos - http://www.flickr.com/photos/slackline/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: skip functions containing missing variables?

Nick Cox
In reply to this post by Michael Costello
We need care over terminology here. A missing variable in your sense is perhaps better described as a variable that is not present in the dataset.

It is easy for a reader to confuse that situation with a variable that is present but contains missing values.

-capture- is probably what you need.

Nick
[hidden email]

Michael Costello

I have about 25 databases with similar (but not exactly the same)
variable lists.  I want to "clean" them up by adjusting labels,
formats, etc.  Is there a way to have stata simply skip an absent
variable so taht I can run the same .do file on every database?  For
example:

one.dta varlist: gender age date grade speed
two.dta varlist: gender date grade speed

Since age is missing from the second database if I run a script saying
"label variable age "How old is the student?" " stata would stop
running because of an error.  Or, if I tried to change the order of
the (present) variables, it would have an error when it came to the
missing age variable.

So is there a way I can avoid this error?  Is there some prefix that
says: Do only when variables are present?


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Loading...