Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: programming with placeholders


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 

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/


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