Statalist


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

Re: st: AW: summing variables that have similar names


From   MAY BAYDOUN <mbaydoun2002@yahoo.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: AW: summing variables that have similar names
Date   Tue, 14 Jul 2009 09:00:19 -0700 (PDT)

Super! Thanks a lot!

May

May Baydoun, PhD in Epidemiology (UNC-Chapel Hill)  Staff Scientist,  National Institute on Aging, NIH/IRP,  Biomedical Research Center,  Baltimore, MD


--- On Tue, 7/14/09, Martin Weiss <martin.weiss1@gmx.de> wrote:

> From: Martin Weiss <martin.weiss1@gmx.de>
> Subject: st: AW: summing variables that have similar names
> To: statalist@hsphsun2.harvard.edu
> Date: Tuesday, July 14, 2009, 11:42 AM
> 
> <> 
> 
> -egen, rowtotal()- happily takes a -varlist- so you can do
> anything you see
> in -help varlist-
> 
> 
> *************
> clear*
> 
> inp x1 x2  y z
> 1 . . .
> . 1 . .
> . . 1 .
> . . . 2
> . . 4 .
> . 3 . .
> 4 . . .
> end   
> egen sumofxyz=/* 
>  */ rowtotal(x* y z)
>  
> l
> *************
> 
> 
> 
> HTH
> Martin
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]
> Im Auftrag von MAY BAYDOUN
> Gesendet: Dienstag, 14. Juli 2009 17:34
> An: statalist@hsphsun2.harvard.edu
> Betreff: st: summing variables that have similar names 
> 
> Dear Statalisters,
> 
> I was wondering if someone can help me figure out this:
> 
> I have several variables that are mutually exclusive. In
> other words, if one
> has a value, the others are missing. I want to sum them
> into a single
> variable so that all observations have a value. They start
> with the same few
> letters, say xyz but have different letters or numbers
> thereafter.
> 
> I tried: gen newvar=sum(xyz*) but it didn't work out. Is
> there another way
> to do this? I am guessing a loop?
> 
> Thanks a lot for any help you can provide,
> 
> Best,
> 
> May
> 
> 
> May Baydoun, PhD in Epidemiology (UNC-Chapel Hill) 
> Staff Scientist,
> National Institute on Aging, NIH/IRP,  Biomedical
> Research Center,
> Baltimore, MD
> 
> 
>       
> *
> *   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/
> 
> 
> *
> *   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/
> 


      

*
*   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   |   What's new   |   Site index