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

st: global variable in a loop


From   Amit Khandelwal <[email protected]>
To   [email protected]
Subject   st: global variable in a loop
Date   Tue, 17 Aug 2004 18:15:26 -0400

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/



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