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: reshape data


From   Ronnie Babigumira <rb.glists@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: reshape data
Date   Mon, 17 Feb 2014 09:38:44 +0100

There will be other ways to do this but here is one which uses the
very useful -sxpose- (-ssc install sxpose-)

************
clear
input str20 v1 v2
EntityID 100091
corpid1 8101
begyr1 1961
gvkey1 1000
endyr1 1970
corpid2 8091
begyr2 1971
gvkey2 1000
endyr2 1973
corpid3 8011
begyr3 1974
gvkey3 1001
endyr3 2000
end

compress
sxpose, clear firstnames force
reshape long corpid begyr gvkey endyr, i(EntityID) j(pd)

**********

    EntityID   pd   corpid   begyr   gvkey   endyr
      100091    1     8101    1961    1000    1970
      100091    2     8091    1971    1000    1973
      100091    3     8011    1974    1001    2000


Hope this helps

Ronnie

On Mon, Feb 17, 2014 at 3:45 AM, R Zhang <r05zhang@gmail.com> wrote:
> Dear All,
> I want to do a merge , the dataset ONE is the using data set.
>
> dataset ONE has the following structure:
>
> EntityID 100091
> corpid1 8101
> begyr1 1961
> gvkey1 1000
> endyr1 1970
> corpid2 8091
> begyr2 1971
> gvkey2 1000
> endyr2 1973
> corpid3 8011
> begyr3 1974
> gvkey3 1001
> endyr3 2000
>
> entityID is a unique company id.Over time, the company may reorganize
> due to merge & acquisition, that is why you see corpid1,2,3 and
> gvkey1,2,3 with the beginning and ending years,that is,
>
> from 1961, to 1970, crpid1 8101 and gvkey1 1000 are effective.
>
> from 1971, to 1973, crpid2 8091 and gvkey2 1000 are effective.
>
> I would like to reshape the data into:
>
> EntityID corpid beginyr  gvkey   endyr
> 100091   8101 1961   1000          1970
> 100091   8091  1971    1000     1973
> 100091   8011  1974    1001     2000
>
> could you help?
>
> thanks a bunch,
>
> -R
> *
> *   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