Statalist


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

st: AW: Using date locals with -tin()-


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Using date locals with -tin()-
Date   Tue, 9 Jun 2009 09:07:34 +0200

<> 

When you -trace- the execution, you see that -tin()- expects the format in
which the data were -tsset- while you are passing it an unformatted date.
You can achieve what you want with the code below, though... See -help
extended_fcn-

*************
// begin example code

// Define today
local today = date(c(current_date),"DMY")
disp `today'
disp %td `today'

local today2: disp %td `today'

// Create synthetic dataset
use sp500, clear
gen datenew = date + int(365.25*8)
format datenew %td
drop date
tsset datenew
order datenew
drop if tin(01jul2009,)

// Display data
list in -15/l                // OK
list if datenew >= `today'   // OK
list if tin(09jun2009,)      // OK


list if tin(`today2',)        // OK
list if tin(`today',)        // Error

// end example code
*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Michael Hanson
Gesendet: Dienstag, 9. Juni 2009 06:51
An: [email protected]
Betreff: st: Using date locals with -tin()-

I would like to get the -tin()- function to recognize the current  
date, such as in the example proposed below.  If you run this example  
today (as in 2009-Jun-09), the first three list commands should yield  
the same results, while the last does not work due to a syntax error.   
I'm guessing that is because `today' evaluates to 18057 instead of  
09jun2009 in the -tin()- function (for today, that is), but I'm not  
sure.  Suggestions on how to use (some form of) the local macro  
`today' inside the -tin()- function would be appreciated.


// begin example code

// Define today
local today = date(c(current_date),"DMY")
disp `today'
disp %td `today'

// Create synthetic dataset
webuse sp500, clear
gen datenew = date + int(365.25*8)
format datenew %td
drop date
tsset datenew
order datenew
drop if tin(01jul2009,)

// Display data
list in -15/l                // OK
list if datenew >= `today'   // OK
list if tin(09jun2009,)      // OK
list if tin(`today',)        // Error


// end example code


Thanks in advance for any assistance.

-- Mike

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


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index