Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: dates in the 'if' condition

From   Nick Cox <>
To   "''" <>
Subject   st: RE: dates in the 'if' condition
Date   Tue, 9 Aug 2011 14:35:20 +0100

One solution is 

. keep if string(time, "%tq") == "1997q4" 

Logic: "1997q4" is a string. So you need a way to map from the numeric variable to a string. The -string()- function will do that for you. 


-----Original Message-----
From: [] On Behalf Of
Sent: 09 August 2011 14:28
Subject: st: dates in the 'if' condition

I have not used Stata in time-series context before and would like to ask
a rather simple thing. Having the time variable in a %tq format, it displays the date label but the underlying value
is a number. I have tried to condition with the `if' statement referring to the label instead of the underlying value, but to no avail. Is there any way to do so?
Here is an example:
              storage  display     value
variable name   type   format      label      variable label
time          float  %tq                    

keep if time==1997q4
1997q4 invalid name

keep if time=="1997q4"
type mismatch

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index