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: Doubts on how to better prepare my dataset with -reshape- and -merge_


From   Roberto Ferrer <refp16@gmail.com>
To   Stata Help <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Doubts on how to better prepare my dataset with -reshape- and -merge_
Date   Sun, 27 Oct 2013 22:35:37 -0430

Try the -string- option with -reshape- . No need to rename (with your
example, at least):

*---------------------------- begin code
--------------------------------------------
clear
input co_id str4 ticker_name str9 return_type returnJun2000
returnJul2000 returnAug2000
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
end


rename return_type rtype

reshape long return, i(co_id rtype) j(yrmonth) string

order ticker_name, after(co_id)
sort co_id rtype
list, noobs sepby(co_id rtype) abbrev(14)


*-------------------------------- end code
-------------------------------------------

On Sun, Oct 27, 2013 at 9:47 PM, Clarice Martins
<martins.clarice@gmail.com> wrote:
> Red Owl, thank you!
>
> I see your point, and it sounds it will work.
>
> The only question is: i do have 151 return periods to type up year and month... is there another way?
>
>> rename returnJun2000 return200006
>> rename returnJul2000 return200007
>> rename returnAug2000 return200008
>
>
>
>
>
> On Oct 27, 2013, at 6:09 PM, Red Owl wrote:
>
>> Clarice,
>>
>> I am not sure I understand what you want, but perhaps this will
>> do it or give you a conceptual approach:
>>
>> clear
>> input co_id str4 ticker_name str9 return_type returnJun2000
>> returnJul2000 returnAug2000
>> 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
>> end
>>
>> rename return_type rtype
>> rename returnJun2000 return200006
>> rename returnJul2000 return200007
>> rename returnAug2000 return200008
>>
>> reshape long return, i(co_id rtype) j(yrmonth)
>>
>> order ticker_name, after(co_id)
>> sort co_id rtype
>> list, noobs sepby(co_id rtype) abbrev(14)
>>
>>
>> Red Owl
>> redowl@liu.edu
>>
>>
>>>>
>>>> Clarice Martins wrote:
>>
>> 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
>> *
>> *   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/
*
*   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