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 at the end of May, 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   Robert Picard <picard@netbox.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 19:15:36 -0400

Normally, I would use -expand- to add observations within the dataset
but from your description it might be simpler to use -collapse- to sum
up your observations and then -append- the new observations to the
original dataset.

Hope this helps,

Robert

*--------------------------- begin example -----------------------
version 11

clear all
sysuse auto

* create identifier to group together observations
gen make1 = word(make,1)

tempfile f
save "`f'"

collapse (sum) price-gear_ratio, by(make1)
append using "`f'"
sort make1 make
*--------------------- end example --------------------------

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

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