Statalist


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

st: RE: Calling local variable in twithin()


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Calling local variable in twithin()
Date   Tue, 14 Oct 2008 18:38:08 +0100

First off, these are, strictly, local macros, not local variables. See
e.g. 

<http://www.stata.com/statalist/archive/2008-08/msg01258.html> 

for a stern homily on such matters. 

That aside, I suspect that you are not telling us everything. The most
common reason for problems like this in my experience is that users are
defining locals within an interactive session and then trying to run
code referring to them from a program, do-file, or the do-file editor.
But then the code in question cannot see the locals in question. 

The posting just cited says a bit more. 

Remember, "local" means precisely that. 

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

Jacob Smith

I have tried to find a solution to how to use a local variable to pass 
two dates to a twithin() statement.

I currently have to pull a date range from a ODBC connection and I am 
trying to use the dates I retrieve to some information from another 
information source. If I manually put in twithin(07oct2008, 17oct2008) I

have no problems, but I cannot seem to get the contents of a local 
variable to work within the twithin() option. I have tried with both the

double representation of a date as well as a string, and it seems almost

any other possible combination with no luck.

Currently this is what I am trying to run:


clear
odbc load, exec("SELECT day, futuredate FROM Table ORDER BY day DESC 
LIMIT 1") dsn("DSN")
scalar da=day
local lda %td da
scalar fd=futuredate
local lfd %td fd

clear
haver use FLODON FLOD1 FLOD3 FLOD6 FLOD1Y using c:\location\of\file.dat,

twithin(`lda' ,`lfd')

Here is what my local variables look like:

. di `lda'
07oct2008
. di `lfd'
17oct2008

and when I use the following I have no problem:

. haver use FLODON FLOD1 FLOD3 FLOD6 FLOD1Y using 
c:\location\of\file.dat, twithin(07oct2008,17oct2008)


Thank you for any help in this matter,

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