| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: xline
Good answers have already been posted, but the question
remains of why you thought that the -xline()- option
might perform in the way you wanted, so that misunderstanding
needs elucidation.
There are two issues here.
The first is that the on-line _help_, here for -axis label options-,
specifies what kind of input is acceptable. The trick that Michael
Blasnik specified
`=d(5jan2007)'
is not explicit in that help, nor should it have been -- unless it is
considered acceptable to spell out almost everywhere
in the help that you can use that trick to specify input. (It could in
principle be relevant to _every_ command.) By the way, I say "trick" but
that is just light-hearted. There is no dodge or work-around: it is
a perfectly straightforward device in Stata.
Understanding why Michael's trick works is perhaps helped by thinking
that there are two steps to take even when the input is something very
simple such as
scatter y t, xline(`=d(5jan2007)')
* One engine, which you might think of as "Stata" or "the interpreter",
looks at what you typed and does various checks and preliminary
processing. These include checking that the command exists, that the
syntax is correct and (pertinently here) carrying out any evaluation of
global or local macros or equivalent expressions. So Stata is
instructed to evaluate d(5jan2007) before passing the command on for
execution. The answer is 17171.
* Another engine, which in this case is -scatter-, sees not what you
typed but
scatter y t, xline(17171)
which is in this case legal as far as it is concerned (and matches one
of the possibilities specified in the help). -scatter- in turn calls
other programs and so on and so forth but that is beyond the story here.
The second issue is precisely when will Stata _evaluate_ what you give
it? The main answers that spring to mind are
* When you refer to local or global macros. You type the name; Stata
inserts the contents in place of the name.
* When you specify evaluation by inserting an expression after an equals
sign (using material allowed in that context). `= <stuff>' you can type
anywhere you like in commands (whether the results will be what you want
is a different matter).
* When it is the command's job to evaluate. -display- is one conspicuous
example.
That's unlikely to be a complete list, but it may help understanding.
Nick
[email protected]
Eric G. Wruck
I am working on a graph & want to insert vertical lines for various
dates, time being the x-axis. It seems xline will not accept
expressions or variable names, as I have tried, for example:
xline(d(5jan2007))
or
xline(scan1)
where scan1 was previously defined in the .do file with
gen scan1 = d(5jan2007)
The only way I get the thing to work is to have xline(17171), but I
don't want to have to look up all the dates by hand. Does someone
know an easier way to handle this?
*
* 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/