Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Storing multiple values in a macro


From   Keith Dear <[email protected]>
To   [email protected]
Subject   Re: st: Storing multiple values in a macro
Date   Mon, 03 Mar 2008 12:52:31 +1100

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.

Keith

At 12:16 PM 3/03/2008, you wrote:

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.

Any ideas?
*
* 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/

Dr Keith B.G. Dear
Senior Fellow in Biostatistics
National Centre for Epidemiology and Population Health
Australian National University
Canberra, ACT 0200, Australia
Tel: 02 612 54865, Fax: 02 612 50740
http://nceph.anu.edu.au/Staff_Students/staff_pages/dear.php
CRICOS provider #00120C

http://canberragliding.org/

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



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