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 Chuntao (Tony)" <[email protected]>
To
[email protected]
Subject
Re: st: How to generate a time variable and merge with another file
Date
Fri, 19 Apr 2013 11:22:51 +0800
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/