Perfect, Michael - thanks.
Michael Blasnik wrote:
The line
local trial=trial2
will set the local macro trial equal to the value of the trial2
variable from the first observation of the dataset. The equals sign
and the lack of quotes makes this a simple assignment where Stata
evaluates the expression (trial2) and comes up with trials2[1]. What
you want is most likely:
local trial "trial2"
which will then substitiute the text (trial2), which is the name of a
variable, whenever it encounters `trial'. This approach should make
your equation work as expected.
Michael Blasnik
[email protected]
----- Original Message ----- From: "Cade Massey" <[email protected]>
To: <[email protected]>
Sent: Monday, November 29, 2004 3:09 PM
Subject: st: local macro vs. database variable
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/
*
* 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/