Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Adding variables with common prefix

From   "R.E. De Hoyos" <>
To   <>
Subject   st: Adding variables with common prefix
Date   Tue, 30 May 2006 13:09:45 +0100

I have a large list of variables with a common prefix, say -var- (var1, var2, var3...). I want to generate a scalar with the sum of these variable's first observation. I tried the following loop, but for some reason that I can't see it is not working, it returns an invalid syntax error message:

local sum = 0
foreach v of var* {
local sum = `sum' + `v'[1]
scalar answer = `sum'

What is wrong with this code? Is there an alternative way of adding up variables with a common prefix?

* For searches and help try:

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