I agree with Keith's comments.
It does not sound as if you really need to store multiple numerical
values in a macro for your purposes.
In any case, here's a further warning:
. local foo 2 -1
. di `foo'
1
. local foo 2 (-1)
. di `foo'
2-1
If some values are negative, watch out. Stata tries its level best in
some contexts to find expressions
and evaluate them. Thus, you are often well advised to wrap negative
numbers in parentheses.
Nick
[email protected]
Keith Dear
First off, you can't really store even a single numerical value in a
macro, except as a string representation. Macros are always strings.
You can store a representation of several numbers by separating them
with spaces, or indeed any character you please including none.
. loc two `=_pi' `=exp(1)'
. di "`two'"
3.141592653589793 2.718281828459045
loc two `:di %6.4f _pi'`:di %6.4f exp(1)'
. di "`two'"
3.14162.7183
Second question: if the match is 1:1 with no extra rows, and the date
intervals don't overlap, you can sort both datasets and then simply
stick them side by side using -merge- with no merge variables: they
should line up properly in date order. It would be wise to check
(-assert-).
Otherwise, if you data is not too large, you may be able to use
-joinby- to build a dataset holding all pairwise combinations of the
two datasets, then throw away the rows (n(n-1) of them) that don't
match.
Malcolm Wardlaw
>I have a two part question.
>
>The first is, I'm wondering how to store multiple numerical values
>in a macro. I know how to do it with string variables, but I'm
>stuck on numbers.
>
>The second is a more general question on a routine I'm trying to run.
>I've constructed a way to do it, but I think it must be terribly
inefficient.
>
>What I'm trying to do is to merge observations based on a range
>instead of a single value. The match is one-to-one, but it involves
>trying to match a single date in between a start and end date in
>another data set. What I did was to loop through each observation
>in the original data set, store the values in a macro, and then
>`use' only the single observation that corresponds to being greater
>than the first date and less then the second. I then tag that
>observation with a code and append it to a new data set. This gives
>me a coded merge-able dataset.
>
>It seems terribly inefficient though. I have to load one dataset,
>clear it, load another, and then save the results to a third dataset
>for each observation.
*
* 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/