Statalist The Stata Listserver


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

st: RE: local variable within a global macro?


From   "Alex Ogan" <[email protected]>
To   <[email protected]>
Subject   st: RE: local variable within a global macro?
Date   Tue, 29 Aug 2006 09:10:19 -0400

Here's one solution, quite likely not the cleanest/shortest, but
functional:

forvalues n = 1/10 {
	local np1 = `n' + 1
	local globalname "X`np1'"
	reg y`n' $X`globalname'
}

HTH
Alex

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nishant Dass
Sent: Tuesday, August 29, 2006 8:55 AM
To: STATA Help
Subject: st: local variable within a global macro?

Dear list-members, 

I have a small (or so it seems) problem with a loop (shown
below).  

I start by generating a few global macros:
global X2 "age2 weight2 height2"
global X3 "age3 weight3 height3"
...
global X11 "age11 weight11 height11"

Then I try to run the following set of regressions using a
loop:
forvalues n = 1/10 {
	local p = `n' + 1
	reg y`n' $X`p'
}

However, this isn't executed due to an error that says "2
invalid name" (i.e., it's referring to some problem in the
way I have used `p' in $X`p'.)

Could anyone please tell me what would be the correct way
to do this?  

Thank you very much for your help.

Nishant


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
*
*   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/


This message is intended solely for the designated recipient(s). It may contain confidential or proprietary information and may be subject to confidentiality protections. If you are not a designated recipient, you may not review, copy, or distribute this message. If you receive this in error, please notify the sender by reply e-mail and delete this message. 

Arrowstreet Capital, L.P. is an Equal Opportunity Employer. 



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