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]

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


From   Steve Samuels <sjsamuels@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How do I create a new observation that is the sum of two observations?
Date   Sat, 1 May 2010 16:56:56 -0400

Try this code.  You have to decide what to do about string variables.
Steve
**************************CODE BEGINS**************************
sysuse auto,clear
gen id= _n
preserve
drop if inlist(id,1,2)
tempfile t1
save `t1'
restore
keep if inlist(id,1,2)
ds, has(type numeric)
foreach v in `r(varlist)'{
replace `v'= sum(`v')
}
keep if _n==_N
list
**replace id = ??
append using `t1'
sum
***************************CODE ENDS***************************

On Sat, May 1, 2010 at 4:06 PM, Aiyar, Shekhar
<Shekhar.Aiyar@bankofengland.co.uk> wrote:
> 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/
>



-- 
Steven Samuels
sjsamuels@gmail.com
18 Cantine's Island
Saugerties NY 12477
USA
Voice: 845-246-0774
Fax:    206-202-4783

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