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

Re: st: summing variables

From   Maarten buis <>
Subject   Re: st: summing variables
Date   Thu, 26 Jul 2007 21:21:30 +0100 (BST)

--- P chrisman <> wrote:
 I need to find the total mg of a treatment received for each subject.
> I have mg of treatment drug as variables mg_1 for the first dose
> received through mg_108 for the last dose received. I would normally
> just create a variable, e.g. gen totalmg= mg_1 + mg_2 to find the
> total, but since I have 108 doses to sum, I am wondering if there is
> a more efficient way to create the totalmg?

gen double totalmg
foreach var of varlist mg_* {
    replace totalmg = totalmg + `var'

Hope this helps,

Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
*   For searches and help try:

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