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: Doubts on how to better prepare my dataset with -reshape- and -merge_
From
Roberto Ferrer <[email protected]>
To
Stata Help <[email protected]>
Subject
Re: st: Doubts on how to better prepare my dataset with -reshape- and -merge_
Date
Sun, 27 Oct 2013 19:56:56 +0000
Clarice,
Maybe you're after -append- and not -merge-.
On Sun, Oct 27, 2013 at 7:15 PM, Clarice Martins
<[email protected]> wrote:
> Hello, list members:
>
> Could anyone give some idea how to better use my data on Stata? (using Stata 12.1)
>
> I have:
> - dataset that is wide
> - i couldn't figure out how to transform it to long using -reshape- because there is 3 variables that uniquely define an observation: co_id (an id per company), period (a month and year period for each observation), and type_return (there are 3 different types of return and for each there is an observation per company, per period)
> - dataset looks like this:
>
> co_id ticker_name return_type returnJun2000 returnJul2000 returnAug2000 (and so on)
> 1 ABCB formation 0.01 0.2 0.3
> 2 AEDU formation 0.01 0.2 0.3
> 3 AMBV formation 0.01 0.2 0.3
> 1 ABCB buysell 0.01 0.2 0.3
> 2 AEDU buysell 0.01 0.2 0.3
> 3 AMBV buysell 0.01 0.2 0.3
> 1 ABCB holding 0.01 0.2 0.3
> 2 AEDU holding 0.01 0.2 0.3
> 3 AMBV holding 0.01 0.2 0.3
>
>
> I tried:
> - dividing in three datasets (one for each type of return: formation, buysell, holding)
> - then, using -reshape- transformed each dataset in long format
> - using this command:
>
> reshape long return, i(co_id) j(period)
>
> - after procedure, it looked like this:
> dataset 1:
> co_id ticker_name return_type period return
> 1 ABCB formation 62000 0.04
> 1 ABCB formation 72000 0.05
> 2 AEDU formation 62000 -0.01
> 2 AEDU formation 72000 -0.02
> 3 AMBV formation 62000 0.01
> 3 AMBV formation 72000 0.01
>
> dataset 2:
> co_id ticker_name return_type period return
> 1 ABCB buysell 62000 0.04
> 1 ABCB buysell 72000 0.05
> 2 AEDU buysell 62000 -0.01
> 2 AEDU buysell 72000 -0.02
> 3 AMBV buysell 62000 0.01
> 3 AMBV buysell 72000 0.01
>
> dataset 3:
> co_id ticker_name return_type period return
> 1 ABCB holding 62000 0.04
> 1 ABCB holding 72000 0.05
> 2 AEDU holding 62000 -0.01
> 2 AEDU holding 72000 -0.02
> 3 AMBV holding 62000 0.01
> 3 AMBV holding 72000 0.01
>
> But now:
> - I have three data sets with same variables, and could not figure out how to merge them into one using -merge-.
>
> Is this the best way to proceed? Any ideas?
>
> Thanks for your consideration.
>
> Regards,
> Clarice
> *
> * 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/