Statalist


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

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


From   Michael Hanson <[email protected]>
To   [email protected]
Subject   Re: st: AW: Using date locals with -tin()-
Date   Tue, 09 Jun 2009 06:50:45 -0400

Thanks, Martin. I figured that was the problem -- should have thought of using trace. When I looked through -help macro- earlier, I couldn't find the necessary syntax to format the date. Appreciate you pointing it out to me. Looks like one can combine the first several lines to:

	local today : disp %td date(c(current_date),"DMY")

That will allow the desired line of code

	list if tin(`today',)

to work, but now the line

	list if datenew >= `today'

will fail.  I can live with that.

Thanks again,
Mike


On Jun 9, 2009, at 3:07 AM, Martin Weiss wrote:

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/



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