Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Add new observations in the dataset


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Add new observations in the dataset
Date   Fri, 19 Jul 2013 10:39:54 +0100

You can do this, but it is a bad idea. I call this spreadsheet
thinking: it is natural to want to see totals on a spreadsheet. But
for data analysis, if you add totals in extra observations you then
have to remember to exclude them from later analyses to avoid double
counting. That is easy to get wrong.

What is much easier to think about is adding a variable with country totals:

egen x1total = total(x1), by(year)

But as a matter of Stata technique: what you outline can be done
without -collapse- and -append-, but the -collapse- and -append- route
is probably the best.
Nick
[email protected]


On 19 July 2013 10:25, Alice Guerra <[email protected]> wrote:
> Dear Statalists,
>
> I have a panel dataset that looks as follows:
>
> year city x1
> 2008 Ancona 5
> 2008 Bari 1
>
> 2009 Ancona 8
> 2009 Bari 3
>
> 2010 Ancona 9
> 2010 Bari 8
>
> I would like to add for each year a new observation "Italy" whose x1'
> values are the sum of the x1's values of Italian cities:
>
> year city x1
> 2008 Ancona 5
> 2008 Bari 1
> 2008 ITALY 6
>
> 2009 Ancona 8
> 2009 Bari 3
> 2009 ITALY 11
>
> 2010 Ancona 9
> 2010 Bari 8
> 2010 ITALY 17
>
> Is there a direct way to obtain this result or I have to use collapse,
> save the dta with only Italy, and append it to the complete dta?
>
> Thank you fot your time and assistance
>
> Best regards
>
> Alice
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index