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 on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: How do I create a new observation that is the sum of two observations?


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: How do I create a new observation that is the sum of two observations?
Date   Sat, 1 May 2010 22:42:37 +0200

<>

You can create new vars with -egen,total()- though, and -drop- the old ones:

***********
clear*
//100 obs
set obs 100

//10 vars
foreach var of newlist var1-var10{
	gen `var'=rnormal()
}

//number for addition
gen number=sum(mod(_n,2)==1)

foreach var of varlist var*{
	bys number: egen new`var'=total(`var')
}

drop var*
keep if !mod(_n,2)


l in 1/10

***********


HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Aiyar, Shekhar
Sent: Samstag, 1. Mai 2010 22:06
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: How do I create a new observation that is the sum of two
observations?

I have a dataset with about 200 observations (rows) and 1000 variables
(columns). I want to add two of those observations (rows) together to create
a new observation. As far as I can make out, gen and egen can only be used
to create new variables, not new observations. Any ideas? Thanks.

Shekhar


****************************************************************************
*******
This e-mail is intended for the addressee(s) named above and any other use
is prohibited. It may contain confidential information. If you  received
this e-mail in error please contact the sender by return e-mail.

The Bank of England does not accept legal responsibility for the contents of
this message if it has reached you via the Internet, as Internet
communications are not secure. Any opinions expressed are those of the 
author and are not necessarily endorsed by the Bank of England.

Recipients are advised to apply their own virus checks to this message .
****************************************************************************
******* 


_____________________________________________________________________
This e-mail has been scanned for known viruses by the Messagelabs SkyScan
Service.

*
*   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   |   Site index