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

st: RE: global variable in a loop


From   "Nichols, Austin" <ANichols@ui.urban.org>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: global variable in a loop
Date   Tue, 17 Aug 2004 18:44:59 -0400

Stata reads $S`j' as $S followed by `j', or zero followed by null.
Try ${S`j'} instead.

-----Original Message-----
From: Amit Khandelwal [mailto:khandelwal.amitk@gmail.com]
Sent: Tuesday, August 17, 2004 6:15 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: global variable in a loop


I have the following code:
	global S_1 "S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12 S13"
	global S1=1.1
	global S2=1.2
	global S3=1.3
	global S4=1.4
	global S5=1.5
	global S6=1.6
	global S7=1.7
	global S8=1.8
	global S9=1.9
	global S10=1.432
	global S11=1.243
	global S12=1.3421
	global S13=1.412
	capture drop index
	gen index=.
	forvalues j=1/13 {
                 bysort destination year: replace
index=sum(prices^(1-$S`j')) if `j'==d2
	}
d2 is a variable that takes values 1-13. So, if d2=4, I need it the
corresponding prices raised to 1-$S2. However, Stata instead makes
$S`j'=1 for all j, so my price variable is being raised to the 0
power. Does anyone know what is wrong with my code?

Thanks,
Amit
*
*   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/



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