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" <[email protected]>
To   "'[email protected]'" <[email protected]>
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:[email protected]]
Sent: Tuesday, August 17, 2004 6:15 PM
To: [email protected]
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?

*   For searches and help try:
*   For searches and help try:

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