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: Stata loop execution, failing to take into consideration all variables
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Stata loop execution, failing to take into consideration all variables
Date
Wed, 2 Mar 2011 13:41:46 +0000
In addition, as I understand it, your various samples overlap. I can't
see that would create your problem, but I think it won't make it
easier.
On Wed, Mar 2, 2011 at 1:28 PM, Nick Cox <[email protected]> wrote:
> I don't have your data, but in any case the bigger issue is how to
> debug a problem like this. I would take your loops and turn them into
> code that spits out what data are being identified. Looking at the
> first few funds should help to identify what is being looked at, say
>
> forvalues f= 1/10 {
> forvalues y=1998(1)2010{
> forvalues m=1(1)12{
> list reg exret mktrf hml smb if
> fundid==`f' & (date>=ym(`y'-3,`m') & date<=ym(`y',`m'))
> }
> }
> }
>
> or (less output, and also less diagnostic, but may reveal a problem)
>
> forvalues f= 1/10 {
> forvalues y=1998(1)2010{
> forvalues m=1(1)12{
> count if fundid==`f' &
> (date>=ym(`y'-3,`m') & date<=ym(`y',`m'))
> }
> }
> }
>
> On Wed, Mar 2, 2011 at 1:11 PM, S.A.J.van Vijfeijken
> <[email protected]> wrote:
>
>
>> 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).
>>
>
*
* 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/