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: Estimating multiple regression on panel dataset by year, saving and testing results.


From   Chipengovich Shpeng <shpenglipeng@yandex.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Estimating multiple regression on panel dataset by year, saving and testing results.
Date   Sat, 12 May 2012 16:54:52 +0400

Good time of the day, I've been using Stata no so long - but I have a research, that requires some programming skills i unfortunately miss.
Analysis concerns market-risk models estimations (CAPM in particular, but I'm stuck even with that one so doesn't follow to Fama-French models and etc)
So that dataset contain weekly return data of numerous stocks (from 100 to 800 depending on dataset) in columns, and columns with corresponding week and year of observation. Looks like following var# stand for stock#, mcsi – for stock index.

year week var1 ... varn mcsi
1        1      .      .    .       .
1        2      .      .    .       . 

The entire task could be described as estimating and testing CAPM model on this data. As to approach I need to use, it is estimation of CAPM models by each year (simple linear correlation of particular stock (var#) with index) and to test them on following year returns. The task could be separated into 2 parts - first one estimating CAPM. So that for each year i need to regress each var on index, then to save the regression results somehow to be useful for further analysis.
That would be nice to have this results for example as a table with stock number, year, beta, r-squared
I only know how to use loop to make regression for the whole data (all years). But even with such a code I got problems – It doesn’t want to allow to trace more than 40 results….

Code I’ve tried:
local symbols = "var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 var12 var13 var14 var15 var16 var17 var18 var19 var20 var21 var22 var23 var24 var25 var26 var27 var28 var29 var30 var31 var32 var33 var34 var35 var36 var37 var38 var39 var40 var41 var42 var43 var44 var45 var46 var47 var48 var49 var50 var51 var52 var53 var54 var55 var56 var57 var58 var59 var60 var61 var62 var63 var64 var65 var66 var67 var68 var69 var70 var71 var72 var73 var74 var75 var76 var77 var78 var79 var80 var81 var82 var83 var84 var85 var86 var87 var88 var89 var90 var91 var92 var93 var94 var95 var96 var97 var98 var99 var100"
foreach ticker in `symbols' {
	reg `ticker' mcsi
	local _b_`ticker'=_b[mcsi]
	local _r_`ticker'=`e(r2)'
}

foreach ticker in `symbols' {
	di "Beta: " %9.4f `_b_`ticker'' "  Rsq: " %9.4f `_r_`ticker'' "  
}
As a result Stata traces 40 regression tables, then gives “ va ambiguous abbreviation “ of red color, and moves to tracing  “Beta” and “Rsq” also for 40 estimations then stops.
Also I’d like to ask, how I could run regressions, using my beta-estimations as coefficients for predicting next year stock returns.
I could imagine we got these beta estimations (I’ve partly did it in excel, for the purpose I’d fail with stata) and as I could see the data for analysis would look like following, so that by each year we need to pich up var#_b of corresponding previous year beta and var#_a and to test regression
Var# (of year n+1, week z) = var#_a(of year n) + var#_b (of year n) * index (of year n+1, week z)

year week var1 ... varn index      var1_a  var1_b   var2_a var2_b...    varn_b v index
1        1      .      .    .       .      betavar1_y1
1        2      .      .    .       .      betavar1_y1
..........................
2         1                                betavar1_y2

Thanks for attention.
*
*   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