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]

st: Stata loop execution, failing to take into consideration all variables


From   "S.A.J.van Vijfeijken" <[email protected]>
To   [email protected]
Subject   st: Stata loop execution, failing to take into consideration all variables
Date   Wed, 02 Mar 2011 14:11:11 +0100

Hi,

As a means of return comparisment in my mutual fund research I am using the Fama-French factors as a measurement of excess return.
 
However, when I want to regress the Fama-French factors for every fund in my database Stata only calculates the values for the first fund number.

The data used is from the CRSP mutual fund data base, monthly mutual fund returns and the monthly Fama-French factors from the website of Kenneth R.  French for the 1995-2010 period. I have used the panel data command tsset to let Stata know I’m using panel data.

The part of the code that does not work is as follows:

gen exret = mret - rf
sort crsp_fundno
egen fundid = group(crsp_fundno)
gen hmlexp = .
gen smbexp = .
gen performance = .

forvalues f= 1(1)11281{
	forvalues y=1998(1)2010{
			forvalues m=1(1)12{
			quietly reg exret mktrf hml smb if fundid==`f' & (date>=ym(`y'-3,`m') & date<=ym(`y',`m'))  
			replace performance = _b[_cons] if e(sample)
			replace hmlexp = _b[hml] if e(sample)
			replace smbexp = _b[smb] if e(sample)
		}		
	}
}

As you can see I want the data for the 1998-2010 period and I have 11281 mutual funds in my data currently. However Stata only calculates the coefficients for the first fund, and leaves all the others as missing(.), the way they are generated. I looked at the Statalist database and the FAQ, however the solutions offered there did not help.
http://www.stata.com/support/faqs/data/foreach.html
I cannot figure out why Stata stops after the first fund and can’t find the error in the code (if there is one).

Thanks for your consideration,

Bas van Vijfeijken

[email protected]
d==`


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index