Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: programming with placeholders

From   Nick Cox <>
To   "''" <>
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". 


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)



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:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index