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: Collapse an unbalanced panel with annual entries into a standard 5-year average dataset


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Collapse an unbalanced panel with annual entries into a standard 5-year average dataset
Date   Sat, 11 Aug 2012 17:53:22 +0100

gen period = floor((year - 1950) / 3)
collapse GDP POP, by(period country)

See also

SJ-3-4  dm0002  . . . . . . . . Stata tip 2: Building with floors and ceilings
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/03   SJ 3(4):446--447                                 (no commands)
        tips for using floor() and ceil()


Nick

On Sat, Aug 11, 2012 at 2:29 PM, Mads Knudsen <[email protected]> wrote:

> Here comes a rookie question which I haven't been able to find an answer
> for in the forum so far (please excuse me if I have overlooked the obvious
> answer):
>
> What I want to do is the quite standard operation of calculating 5-year and
> 3-year means by country id. I believe that Jeanty's module "paverage" does
> the job if one has a balanced panel dataset. However it does not seem to
> work for my unbalanced panel.
>
> To illustrate:
> I have a data set of this kind (an unbalanced panel in long format):
>
> Country          Year          GDP          POP
> AFG              1950             2               6
> AFG              1951                              7
> AFG              1952             2               4
> AFG              1953             2               3
> AFG              1954             6               6
> AFG              1955             4               7
> ALB               1950            9               9
> ALB               1951            8               6
> ALB               1952           10
> ALB               1953           12               3
> ALB               1954           13               2
> ALB               1955                             5
>
> which I would like to (easily) transform into a calculated dataset of
> the following kind:
>
> country    period          GDP3yrav       POP3yrav
> AFG         1950-52         2              5,666667
> AFG         1953-55         4              5,333333
> ALB          1950-52         9                 7,5
> ALB          1953-55       12,5           3,333333
>
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index