Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: local macro vs. database variable


From   Cade Massey <cade.massey@duke.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: local macro vs. database variable
Date   Mon, 29 Nov 2004 15:09:20 -0500

Can anyone tell me why the following two sub-routines would generate different results? This code is buried in the middle of a long estimation program. I'm trying to get away with imposing on you as little of the program as possible -- not sure if this will be enough to tell. "trial2" is a variable in the dataset.

Original approach:
.gen double `dum1'=$A1*(k1+k2+k3+k4)+$C1*trial2

Modified approach:
.local trial=trial2
.gen double `dum1'=$A1*(k1+k2+k3+k4)+$C1*`trial'

The original approach works fine, but I need to modify it as I write a new program. In case it is of any help, I have one additional clue: the residual SS is the same for both programs on Iteration 0, but grows steadily apart after that. The modified approach provides a poorer fit and requires more iterations to converge.

I'd guess that I'm doing tomething wrong by substituting a local macro for a variable, but I seem to need that variable in a macro. Or maybe I don't. Leads me to a highly related question: If I have 20 local macros defined as `parm1' - `parm20', where the suffix indexes a "trial" variable in the dataset, what is the best way to call those macros in my program? If trial is a local macro, I can use:

gen double `dum1'=`parm`trial''.

But with "trial" as a variable, I haven't been able to find a syntax that works. So I need to learn either 1) how to use a variable value as a suffix in a local macro name, or 2) how to create a local macro that stands in for a variable.

Thanks.
*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index