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: How to generate a time variable and merge with another file


From   LI Mengjia <[email protected]>
To   [email protected]
Subject   Re: st: How to generate a time variable and merge with another file
Date   Sat, 20 Apr 2013 01:02:41 +0800

Dear Tony,

Many thanks for your help. I tried the codes, stata responded "month already defined" when running "by Stockholding ym: gen month=ym-_n+1". I think this is caused by the previous "gen int month = Reporttime-year*100". So I changed the "gen month=ym-_n+1" to "gen moon=ym-_n+1" and the rest. But it turned out to be this situation:

in the new column ym, values ranged from - 10776 to 611;
and it can not merge successfully with return.dta (which I followed the codes before "expand 36" to transfer its month format). The return column remained blank

Is there anything that I might misunderstand?

Looking forward to your reply.

Thanks again and regards,
Mengjia

在 2013-4-19,上午11:22,Li Chuntao (Tony) <[email protected]> 写道:

> For the report time, i suggest you transfer it into stata's month
> format, try the following code
> gen int year =  Reporttime/100
> gen int month = Reporttime-year*100
> gen ym=ym(year, month)
> 
> expand 36
> 
> sort Stockholding ym
> by   Stockholding ym: gen month=ym-_n+1
> drop ym
> rename month ym
> 
> sort Stockholding ym
> merge Stockholding ym using retun.dta
> drop _m
> 
> BTW, i suggest you change your name to Li Mengjia, not the Chinese Characters
> 
> 
> On Thu, Apr 18, 2013 at 11:14 PM, 李 梦佳 <[email protected]> wrote:
>> Dear Statalist,
>> 
>> I have data in the following structure and wish to add a column with inputting the months
>> 
>> Current data:
>> Fund            Stockholding    Reporttime
>> ------------------+-------------------------------
>> 000011.OF       000001          200506
>> 000011.OF      000002           200506
>> ⋯⋯
>> 660001.OF       600002          201012
>> 
>> For each Reporttime (semi-annual), I wish to merge from another dta. with its past 36 monthly returns, to make this  like the following:
>> 
>> Fund            Stockholding    Reporttime      Month   Return
>> ------------------+----------------------------------------------------------------
>> 000011.OF       000001          200506         2005-06          r1
>> 000011.OF       000001          200506         2005-05          r2
>> ⋯⋯
>> 000011.OF       000001          200506         2002-07          rn
>> ⋯⋯
>> 660001.OF       000002          201012          2008-01           rx
>> 
>> Now I have used "expand 36" to create 36 lines for each stock at each reporttime. How can I generate the last column "Month" and further using the stockholding (code) and Month as the link to merge the other file with returns data?
>> 
>> Many thanks and best regards,
>> Amy
>> 
>> 
>> 
>> *
>> *   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