Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Stata doesn't complain about non-existent value label


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Stata doesn't complain about non-existent value label
Date   Thu, 17 Jul 2008 15:49:38 +0100

Good question. Here's a stab. 

One answer is why should it? 

You don't expect 

... if value == 42 

to bounce because it so happens that there is no such value as 42 in
your data. 

It is true that 

... if myvar == 42 

will bounce if there is no such variable (or scalar). 

So, StataCorp has to be draw a line between these situations. Evidently
the decision was that your problem is more like the first than the
second. 

Another answer is that Stata is checking syntax, not semantics. 

... if value == 42 is perfectly good syntax. 

... if live_status == "Alive":live_statusw is also. It just does not
give you want 
For your data. 

... if myvar == 42 will not be good syntax whenever Stata can't make
sense of it, which will be the case if it doesn't know what -myvar- is. 

You can't expect a syntax checker to have a data checker in thrall....

Nick
n.j.cox@durham.ac.uk  

Clyde Schechter

This isn't a question--it's a warning about something that bit me, and a
hope that Stata will change it in the future.  (Or perhaps somebody will
explain why it's actually a useful feature.)

The following command:

gen obs_interval = last_follow_up - first_visit if live_status ==
"Alive":live_statusw

resulted in obs_interval being set to missing for all observations
because
there is no such value label in the dataset as live_statusw.
live_statusw
was a typographical error--I meant to type live_status.  (The reason the
problem wasn't obvious immediately is that subsequent replace
obs_interval
= statements led to most records having a value for obs_interval, so
that
the incorrectly missing values didn't make things go clearly wrong until
many analyses later.)

Why doesn't Stata cease execution and complain that there is no such
value
label, just as it does if I try to use a non-existent variable name.
(OK,
Stata will allow abbreviated variable names, but "live_statusw" is not
the
abbreviation of any existing value label in the data set either.)  Is
there some purpose to having Stata allow reference to non-existent value
labels?  (I'm referring to the non-existence of the value label set
live_statusw here. I understand why a reference to "xxx":live_status
should not lead to an error even if live_status does not include "xxx"
among its possible values.)


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



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