[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"David E Moore" <davem@hartman-group.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: RE: Re: RE: Avoiding loops (the while loop) |

Date |
Mon, 28 Jun 2004 15:22:43 -0700 |

While I still don't quite understand the nature of your data and problem, it seems to me that you should be able to manipulate the data so that properly constructed dummy variables (to identify each month and portfolio) and interactions between pbeta and the appropriate dummy variables could give you exactly what you want in a single regression. It would be large (10 x 12 x 2 coefficients), but it should run considerably faster. > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Subhankar > Nayak > Sent: Saturday, June 26, 2004 6:24 AM > To: statalist@hsphsun2.harvard.edu > Cc: n.j.cox@durham.ac.uk > Subject: st: Re: RE: Avoiding loops (the while loop) > > > Hello Nick, > > Thanks for your suggestions. > > 1) Yes, there are 21 variables. Sorry, it was a typo on my part. > > 2) I want to avoid loops because this is part of a simulation exercise, and > loops in stata (as in any other statistical package) is very slow. First, I > have to do month by month regression for 1000 months. Second, I have to > repeat this exercise for 1000 simulation rounds. Now, even with 1500MB > memory I am allocating, the whole exercise takes 8-10 hours... And I have > variations of these tests. > > 3) Let me try the code you are suggesting. > > 4) I am attaching my code below for perusal if necessary. > > Thank you so much. > Subh > > ---------------------------------------------------------------------------- > -------- > > DATASET: > > Variables Nobs > month 1000 > ret1 1000 > ret2 1000 > ret3 1000 > ret4 1000 > ret5 1000 > ret6 1000 > ret7 1000 > ret8 1000 > ret9 1000 > ret10 1000 > pbeta1 1000 > pbeta2 1000 > pbeta3 1000 > pbeta4 1000 > pbeta5 1000 > pbeta6 1000 > pbeta7 1000 > pbeta8 1000 > pbeta9 1000 > pbeta10 1000 > > Note: 1-10 denote 10 asset portfolios ("port") each month > > GOAL: > 1) Each month, collect the intercept and coefficient of regression of > returns ("ret") on postbetas ("pbeta") > 2) Get the time-series average and t-statistic of this intercept and > coefficient > > > PART OF THE PROGRAM CODE: > > * INITIAL DATA ANALYISIS > /* details skipped */ > > * RESHAPE THE DATASET > sort month > reshape long ret pbeta, i(month) j(port) > sort month port > > * CROSS-SECTIONAL TEST 1: full-period cross-sectional regression > /* details skipped, works fine */ > > * CROSS-SECTIONAL TEST 2: stacked cross-sectional regression > /* details skipped, works fine */ > > * CROSS-SECTIONAL TEST 3: averaged monthly cross-sectional regressions > (Fama-French approach) > /* this is where I want to avoid the while loop, it gets very slow */ > > * Collect the monthly intercepts and slopes > > quietly generate tslope = . > quietly generate tintcp = . > quietly summ month > local nummns = r(max) > sort month port > local imonth = 1 > while `imonth' <= `nummns' { > quietly reg ret pbeta if month == `imonth' > sca e_coeff1 = _b[_con] > sca e_coeff2 = _b[pbeta] > quietly replace tintcp = e_coeff1 if month == `imonth' > quietly replace tslope = e_coeff2 if month == `imonth' > sca drop e_coeff1 e_coeff2 > local imonth = `imonth' + 1 > } > > * Now test the time series of these intercepts and slopes > > quietly replace tslope = . if port ~= 1 > quietly replace tintcp = . if port ~= 1 > quietly summ tintcp if tintcp ~= . > sca sl31 = r(mean) > quietly ttest tintcp = 0 if tintcp ~= . > sca ts31 = r(t) > sca pv31 = r(p) > quietly summ tslope if tslope ~= . > sca sl32 = r(mean) > quietly ttest tslope = 0 if tslope ~= . > sca ts32 = r(t) > sca pv32 = r(p) > drop tslope tintcp > > /* REMAINING ANALYSIS FOLLOWS */ > > > > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > > > * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: Re: RE: Re: RE: Avoiding loops (the while loop)***From:*"Subhankar Nayak" <nayak@bellsouth.net>

**References**:**st: Re: RE: Avoiding loops (the while loop)***From:*"Subhankar Nayak" <nayak@bellsouth.net>

- Prev by Date:
**st: INEQDECO: GINI Inequality Index Question** - Next by Date:
**st: Re: RE: Re: RE: Avoiding loops (the while loop)** - Previous by thread:
**st: Re: RE: Avoiding loops (the while loop)** - Next by thread:
**st: Re: RE: Re: RE: Avoiding loops (the while loop)** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |