Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: multivariate normal regression with ml, linear form


From   Maarten buis <[email protected]>
To   [email protected]
Subject   RE: st: multivariate normal regression with ml, linear form
Date   Wed, 18 Feb 2009 19:50:58 +0000 (GMT)

--- On Wed, 18/2/09, Carlo Fezzi <[email protected]> wrote:
> I am trying to check what the code does and therefore look
> into the macro `u_k' to make sure it contains what I want.
> In this simple case I want it to contain "u1 u2 u3".
> So I am typing:
> 
> -----
> clear
> 
> scalar u1 = 1
> scalar u2 = 5
> scalar u3 = -1
> 
> local u_k "u1"
> 
> forvalues i = 2/3 {
> 	local u_k "`u_k' u`i'"
> 	display `u_k'
>       }
> 
> display `u_k'
> -----
> 
> Why when I ask Stata to display the macro content inside
> the loop it works fine but when I ask it just after the
> loop, Stata does not return any value?

I am assuming you ran the forvalues loop from a .do file and
afterwards, interactively asked fo the display of `u_k'. The
thing about a local macro is that it is local, also local to
a run of a .do file. So, if you do your entire example in one
go you'll find that it does what you asked it to do.

As an aside: The aim of this loop is to create a string 
containing the parts you want to feed to -args-. You can more
directly see the string using -display- if you surround the 
local with quotes, like this:

*---------- begin example -----------
local u_k "u1"

forvalues i = 2/3 {
	local u_k "`u_k' u`i'"
	display "`u_k'"
      }

display "`u_k'"
*---------- end example --------------

-- Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------




      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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