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: Using -exapand


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Using -exapand
Date   Thu, 23 May 2013 13:56:15 +0100

Something like

bysort Focalfirm technology : replace year = year[1] + _n - 1

Note that the technique here is covered by an FAQ, although that's not
necessarily obvious from the title:

How can I replace missing values with previous or following nonmissing
values or within sequences?
http://www.stata.com/support/faqs/data-management/replacing-missing-values/
Nick
njcoxstata@gmail.com


On 23 May 2013 13:31, James Bernard <jamesstatalist@gmail.com> wrote:
> Hi,
>
> I am trying to use -expand to replicate observations:
>
> Focalfirm   Technology  year        n
> -------------    --------------   ---------   -------------
>
> Toyota  XYZ     1990    1
> Toyota  XYZ             1991    4
> Toyota  ZZZ             1990            --
> VW      ABC     1999            2
> VW      CDE     1998            3
>
>
> The idea is that I want to repeat each observation n times. However,
> the new observation must have an updated year number too. That is, the
> second observation must be repeated 4 times (including the original
> observation, of course), but the year must be updated. So, the next
> observations would be identical to the original one, except that their
> year will be 1992, 1993 and 1994.
>
> Using -expand,
>
> -expand n, generate(id)
>
> this is what I get
>
>
> Focalfirm       Technology      year    n       id
> Toyota  XYZ                    1990     1       0
> Toyota  XYZ                    1991     4       0
> Toyota  ZZZ                    1990             0
> VW             ABC                     1999     2       0
> VW             CDE                     1998     3       0
> Toyota  XYZ                    1991     4       1
> Toyota  XYZ                    1991     4       1
> Toyota  XYZ                    1991     4       1
> VW             ABC                     1999     2       1
> VW            CDE                      1998     3       1
> VW            CDE                      1998     3       1
>
>
>
> This is fine, except that the years are not updated. Any idea how I can do this?
>
> Thanks,
> James
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index