Dear all,
I'm new to state and the stata forum so I hope I can present my situation clearly.
I'm trying to replicate the J-K strategy of Jagadeesh and Titman (1993). So sorting stock returns on the past J period, using the top and bottom decile of calculating portfolio return. Long in top 10% short in bottom 10%, and holding it for K period. Here I'm focusing on using weekly data in stead of monthly data. I use data from the CRSP database from all stocks with share code 10 & 11 from 2009-2010 (example data set for building my model).
For so far I succeeded in producing the momentum return for on particular J/K values. J=5 and K=5 thereby skipping 1 value S=1, to correct for possible reversal effect. The values for J/K/S are here an example, at this moment I'm only building the model. I use the variables: permno date prc
permno date prc
10001 02jan2009 8.270000458
10001 05jan2009 8.380000114
10001 06jan2009 8.488800049
10001 07jan2009 8.409999847
10001 08jan2009 8.350000381.....
10002 02jan2009 14.35999966
10002 05jan2009 14.72999954
10002 06jan2009 13.48999977
10002 07jan2009 11.46000004
10002 08jan2009 12.17000008
10002 09jan2009 10.51000023
10002 12jan2009 10.03999996
10002 13jan2009 10.52999973
10002 14jan2009 9.779999733
I have some questions.
1) How to transform my data to date with an business calendar? Because I use now the by permno: gen retJ5S1=prc[_n-1]/prc[_n-6]-1 by permno: gen retS1K5=[prc[_n+5]/prc[_n-0]]-1. codes for calculating returns. Because when I want to use lag or forward functions I don not get the correct results, because of stock prices have no data on saterdays and sundays. This code does work but from reading the forum I notice that the lag en forward functions are better.
I've been searching in this forum for a solution but I can't figure it out. When using some commands mentioned I get these results:
freduse SP500
file __000000.txt could not be opened
file with temporary name already exits
rename files that begin with __ r(498);
sysuse sp500
no; data in memory would be lost
r(4);
2) I'm now using only J=5 S=1 and K=5. But eventually I want to analyze different strategies. How could I loop this code for different values of J/S/K? Example J=5,10,15,20,25...S=5,10,15,20, K=5,10,15,20,25...
3) For the ones who used CRSP database before. I get some extreme returns using the prices of stock presented by CRSP. Some of these extreme results are a result of a splitting of stock (I guess). Here you see that the stock price is declining from 40 to 5 (example). Is there a possibility to correct for these stock splits?
4) The collapse function calculates the mean of the accumulated returns of the K period. Is there a possibility to give the stock a value based weight?
The code I use:
sort permno date
tsset permno date, daily
tsfill
replace prc = -prc if prc<0
drop if prc >=.
gen newtimevariable =_n
tsset newtimevariable
sort permno date
generate dow = dow(date)
** to delete stocks who are not consistent, 5 days= trading week***
sort permno date
by permno: egen maxgap=max(date-date[_n-1])
drop if maxgap> 5
** drop data when there are less than x amount of days of data, here x=30**
by permno: egen cnt = count(permno)
drop if cnt<30
**Gen cumulative return J=5 S=1 & gen cumulative return of K=5 when having S=1**
by permno: gen retJ5S1=prc[_n-1]/prc[_n-6]-1
by permno: gen retS1K5=[prc[_n+5]/prc[_n-0]]-1
*Create 10 quantiles, here quantile 1=losers 10=winners*
egen portfolio= xtile(retJ5S1), nquantiles (10) by (date)
//use only wednesdays//
keep if dow==3
collapse (mean) retS1K5 , by(date portfolio)
drop if portfolio==2
drop if portfolio==3
drop if portfolio==4
drop if portfolio==5
drop if portfolio==6
drop if portfolio==7
drop if portfolio==8
drop if portfolio==9
drop if portfolio==.
reshape wide retS1K5, i(date) j(portfolio)
gen Rmom= retS1K510- retS1K51
Thank you very much for any suggestions or tips.
Gr.
B.E.Uijterschout
University of Groningen
Department of finance
I'm new to state and the stata forum so I hope I can present my situation clearly.
I'm trying to replicate the J-K strategy of Jagadeesh and Titman (1993). So sorting stock returns on the past J period, using the top and bottom decile of calculating portfolio return. Long in top 10% short in bottom 10%, and holding it for K period. Here I'm focusing on using weekly data in stead of monthly data. I use data from the CRSP database from all stocks with share code 10 & 11 from 2009-2010 (example data set for building my model).
For so far I succeeded in producing the momentum return for on particular J/K values. J=5 and K=5 thereby skipping 1 value S=1, to correct for possible reversal effect. The values for J/K/S are here an example, at this moment I'm only building the model. I use the variables: permno date prc
permno date prc
10001 02jan2009 8.270000458
10001 05jan2009 8.380000114
10001 06jan2009 8.488800049
10001 07jan2009 8.409999847
10001 08jan2009 8.350000381.....
10002 02jan2009 14.35999966
10002 05jan2009 14.72999954
10002 06jan2009 13.48999977
10002 07jan2009 11.46000004
10002 08jan2009 12.17000008
10002 09jan2009 10.51000023
10002 12jan2009 10.03999996
10002 13jan2009 10.52999973
10002 14jan2009 9.779999733
I have some questions.
1) How to transform my data to date with an business calendar? Because I use now the by permno: gen retJ5S1=prc[_n-1]/prc[_n-6]-1 by permno: gen retS1K5=[prc[_n+5]/prc[_n-0]]-1. codes for calculating returns. Because when I want to use lag or forward functions I don not get the correct results, because of stock prices have no data on saterdays and sundays. This code does work but from reading the forum I notice that the lag en forward functions are better.
I've been searching in this forum for a solution but I can't figure it out. When using some commands mentioned I get these results:
freduse SP500
file __000000.txt could not be opened
file with temporary name already exits
rename files that begin with __ r(498);
sysuse sp500
no; data in memory would be lost
r(4);
2) I'm now using only J=5 S=1 and K=5. But eventually I want to analyze different strategies. How could I loop this code for different values of J/S/K? Example J=5,10,15,20,25...S=5,10,15,20, K=5,10,15,20,25...
3) For the ones who used CRSP database before. I get some extreme returns using the prices of stock presented by CRSP. Some of these extreme results are a result of a splitting of stock (I guess). Here you see that the stock price is declining from 40 to 5 (example). Is there a possibility to correct for these stock splits?
4) The collapse function calculates the mean of the accumulated returns of the K period. Is there a possibility to give the stock a value based weight?
The code I use:
sort permno date
tsset permno date, daily
tsfill
replace prc = -prc if prc<0
drop if prc >=.
gen newtimevariable =_n
tsset newtimevariable
sort permno date
generate dow = dow(date)
** to delete stocks who are not consistent, 5 days= trading week***
sort permno date
by permno: egen maxgap=max(date-date[_n-1])
drop if maxgap> 5
** drop data when there are less than x amount of days of data, here x=30**
by permno: egen cnt = count(permno)
drop if cnt<30
**Gen cumulative return J=5 S=1 & gen cumulative return of K=5 when having S=1**
by permno: gen retJ5S1=prc[_n-1]/prc[_n-6]-1
by permno: gen retS1K5=[prc[_n+5]/prc[_n-0]]-1
*Create 10 quantiles, here quantile 1=losers 10=winners*
egen portfolio= xtile(retJ5S1), nquantiles (10) by (date)
//use only wednesdays//
keep if dow==3
collapse (mean) retS1K5 , by(date portfolio)
drop if portfolio==2
drop if portfolio==3
drop if portfolio==4
drop if portfolio==5
drop if portfolio==6
drop if portfolio==7
drop if portfolio==8
drop if portfolio==9
drop if portfolio==.
reshape wide retS1K5, i(date) j(portfolio)
gen Rmom= retS1K510- retS1K51
Thank you very much for any suggestions or tips.
Gr.
B.E.Uijterschout
University of Groningen
Department of finance