Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: 'if' with labels but finds no observations


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: 'if' with labels but finds no observations
Date   Fri, 23 Apr 2004 19:07:49 +0100

There is no reason to expect -if- to accept
value labels in this way. Unless explicitly 
instructed, -if- deals with values, not 
value labels. Thus 

if ncyear == 2000/1 

is being interpreted as 

if ncyear == 2000 

as the expression 2000/1 evaluates
to 2000. On the other hand you evidently 
have no years that are 2001/2, i.e. 1000.5. 

The syntax is 

if <exp> 

where <exp> denotes an expression, which will 
be evaluated before being used. 

On the other hand, something like this 
should work: 

tab ncyear if ncyear == "2000/1":name

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

Paul O'Brien
 
> I am not sure what the problem is here, but 'if' is not working for   
> some date labels.
> year_f is OK up to 2000/1 but beyond that give no observations.
> 
> .egen year_f = ncyear(date_v), m(4)
> 
> . table year_f
> ----------------------
>   year_f |     Freq.
> ----------+-----------
>  1997/98 |    44,023
>  1998/99 |    42,654
>   1999/0 |    42,944
>   2000/1 |    42,127
>   2001/2 |    41,520
>   2002/3 |    41,463
>   2003/4 |    40,057
> ----------------------
> 
> . table ageint if year_f==2000/1
> 
> ----------------------
>   ageint |     Freq.
> ----------+-----------
>       12 |         5
>       13 |        36
>       14 |       131
>       15 |       346
> etc
> 
> . table ageint if year_f==2001/2
> 
> no observations
> 
> r(2000);
> 
> But there are observations for year_f==2001/2
> 
>  . table ageint year_f
> 
> --------------------------------------------------------------
> ---------- 
> -
>            |                            year_f
>     ageint | 1997/98  1998/99   1999/0   2000/1   2001/2   2002/3    
> 2003/4
> ---------- 
> +--------------------------------------------------------------
>         10 |       1        1                          2      
>   1         
> 1
>         11 |       2        2        2                 1      
>   2         
> 1
>         12 |       2        3        2        5        4      
>   3         
> 7
>         13 |      13       20       17       36       22      
>  20        
> 12
>         14 |      73       49       64      131      110      
> 101        
> 99
>         15 |     238      259      238      346      362      
> 302       
> 325
> 
> If I try -list- I get the same thing:
> 
> . list if year_f==2000/1
> 
>  Observation 129622
> 
>    clin_s~e          RC   clin_w~k                  connum    
>        2   
>      date   15-Feb-01        dob   04-Apr-63
> 
> etc
> 
>  
> Observation 129623
> 
>    clin_s~e          RC   clin_w~k       D- 
> CON     connum           1       date   07-Feb-01        dob   06-Apr 
> -77
> 
> etc
> 
> . list if year_f==2001/2
> 
> This last command gives nothing.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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