Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: programming with placeholders
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: programming with placeholders
Date
Thu, 27 Oct 2011 13:28:43 +0100
This wasn't part of Fortran when I last used it last century. # signs cannot be used in Stata names, here variable names.
What you want doesn't require any looping whatsoever, and is
bysort LoadPort: egen totalFixtureCar = total(FixtureCar)
See -help egen- and for "STATA" read "Stata".
Nick
[email protected]
Parker, Sophie
I'm new to programming in STATA. I would like to loop through the values of a string variable and use these as the name of the new var. In Fortran, this is the pound sign and variable name. The example is trying to sum all
the cargo shipments for each respective port over a time period, and creates a new var named sum#LoadPort - i.e., sumSingapore.
for i = 1/200
while LoadPort(i+1) = LoadPort(i)
gen sum#LoadPort = sum(FixtureCar)
end
end
I suppose this could also be done by generating variables from a two-way table but it'd be good to know if there's a way around this. Thanks for your consideration.
*
* 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/