|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: AW: fm regression code
<>
Quite possibly, -statsby- does exactly what you want:
*************
clear*
input companyid monthlydate monthlyca monthlydy monthlytr lnmc
54 -1608 0.000 0.000 0.000 9.210
54 -1607 0.000 0.000 0.000 9.210
54 -1608 0.000 0.000 0.000 9.210
54 -1597 0.625 0.000 0.625 9.210
54 -1605 0.000 0.000 0.000 9.210
54 -1604 0.500 0.000 0.500 9.210
54 -1601 -0.429 0.000 -0.429 9.210
54 -1600 0.000 0.000 0.000 9.210
54 -1603 0.625 0.000 0.625 9.210
54 -1602 0.000 0.000 0.000 9.210
54 -1606 0.000 0.000 0.000 9.210
54 -1598 0.000 0.000 0.000 9.210
54 -1599 0.000 0.000 0.000 9.210
120 -1608 0.133 0.000 0.133 11.884
120 -1607 -0.100 0.000 -0.100 11.884
120 -1608 -0.065 0.000 -0.065 11.884
120 -1597 -0.250 0.000 -0.250 11.884
120 -1605 -0.389 0.000 -0.389 11.884
120 -1604 0.000 0.000 0.000 11.884
120 -1601 0.034 0.000 0.034 11.884
120 -1600 -0.172 0.000 -0.172 11.884
120 -1603 0.000 0.000 0.000 11.884
120 -1602 0.227 0.000 0.227 11.884
120 -1606 -0.118 0.000 -0.118 11.884
120 -1598 0.000 0.000 0.000 11.884
141 -1608 0.000 0.000 0.000 10.779
141 -1607 0.000 0.000 0.000 10.779
141 -1608 0.000 0.000 0.000 10.779
141 -1597 0.000 0.000 0.000 10.779
141 -1605 -0.043 0.000 -0.043 10.779
141 -1604 0.000 0.000 0.000 10.779
141 -1601 0.000 0.000 0.000 10.779
141 -1600 0.000 0.000 0.000 10.779
141 -1603 -0.233 0.000 -0.233 10.779
141 -1602 0.000 0.000 0.000 10.779
141 -1606 0.000 0.000 0.000 10.779
141 -1598 0.000 0.000 0.000 10.779
144 -1599 0.000 0.000 0.000 10.714
145 -1608 -0.111 0.003 -0.108 12.075
145 -1607 0.020 0.005 0.026 12.075
145 -1608 -0.020 0.005 -0.015 12.075
145 -1597 0.000 0.004 0.004 12.075
145 -1605 0.000 0.005 0.005 12.075
145 -1604 -0.083 0.005 -0.078 12.075
145 -1601 -0.027 0.004 -0.022 12.075
145 -1600 -0.058 0.004 -0.054 12.075
145 -1603 0.000 0.005 0.005 12.075
145 -1602 -0.020 0.005 -0.015 12.075
145 -1606 -0.009 0.004 -0.004 12.075
145 -1598 -0.082 0.003 -0.078 12.075
147 -1599 -0.167 0.000 -0.167 10.897
165 -1602 0.000 0.000 0.000 9.433
165 -1597 0.000 0.000 0.000 9.433
165 -1604 0.000 0.000 0.000 9.433
165 -1608 -0.429 0.000 -0.429 9.433
165 -1601 0.000 0.000 0.000 9.433
165 -1606 0.000 0.000 0.000 9.433
165 -1605 0.000 0.000 0.000 9.433
165 -1600 0.000 0.000 0.000 9.433
165 -1607 -0.429 0.000 -0.429 9.433
165 -1603 0.000 0.000 0.000 9.433
165 -1599 0.000 0.000 0.000 9.433
165 -1598 0.000 0.000 0.000 9.433
end
compress
list in 1/20, noobs
statsby _b e(N) e(r2_a), /*
*/ by(monthlydate) clear :/*
*/ reg monthlytr lnmc
l, noo
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von qing ye
Gesendet: Dienstag, 4. August 2009 13:38
An: [email protected]
Betreff: st: fm regression code
hi, I want to run a fama -macbeth regression every month and store the
coefficients and number of observations, adjusted R2 in a matrix.
each row of the matrix corrspond to the result from each month.
I typed the following code, but it always gives the invalid syntax
message. Can you tell me what's wrong with the code?
forvalues monthlydate = -1609+ ? i ? {
reg monthlytr lnmc
matrix coefficient =e(b)
matrix regression_result [ ? i ?, 1] =coefficient [1 ,1]
matrix regression_result [ ? i ?, 2] =coefficient [1 ,2]
matrix regression_result [ ? i ?, 3] = e(N)
matrix regression_result [ ? i ?, 4] = e(r2_a)
i = ? i ? +1
}
matrix list regression_result
here is a sample of the dataset
companyid monthlydate monthlyca monthlydy monthlytr lnmc
54 -1608 0.000 0.000 0.000 9.210
54 -1607 0.000 0.000 0.000 9.210
54 -1608 0.000 0.000 0.000 9.210
54 -1597 0.625 0.000 0.625 9.210
54 -1605 0.000 0.000 0.000 9.210
54 -1604 0.500 0.000 0.500 9.210
54 -1601 -0.429 0.000 -0.429 9.210
54 -1600 0.000 0.000 0.000 9.210
54 -1603 0.625 0.000 0.625 9.210
54 -1602 0.000 0.000 0.000 9.210
54 -1606 0.000 0.000 0.000 9.210
54 -1598 0.000 0.000 0.000 9.210
54 -1599 0.000 0.000 0.000 9.210
120 -1608 0.133 0.000 0.133 11.884
120 -1607 -0.100 0.000 -0.100 11.884
120 -1608 -0.065 0.000 -0.065 11.884
120 -1597 -0.250 0.000 -0.250 11.884
120 -1605 -0.389 0.000 -0.389 11.884
120 -1604 0.000 0.000 0.000 11.884
120 -1601 0.034 0.000 0.034 11.884
120 -1600 -0.172 0.000 -0.172 11.884
120 -1603 0.000 0.000 0.000 11.884
120 -1602 0.227 0.000 0.227 11.884
120 -1606 -0.118 0.000 -0.118 11.884
120 -1598 0.000 0.000 0.000 11.884
141 -1608 0.000 0.000 0.000 10.779
141 -1607 0.000 0.000 0.000 10.779
141 -1608 0.000 0.000 0.000 10.779
141 -1597 0.000 0.000 0.000 10.779
141 -1605 -0.043 0.000 -0.043 10.779
141 -1604 0.000 0.000 0.000 10.779
141 -1601 0.000 0.000 0.000 10.779
141 -1600 0.000 0.000 0.000 10.779
141 -1603 -0.233 0.000 -0.233 10.779
141 -1602 0.000 0.000 0.000 10.779
141 -1606 0.000 0.000 0.000 10.779
141 -1598 0.000 0.000 0.000 10.779
144 -1599 0.000 0.000 0.000 10.714
145 -1608 -0.111 0.003 -0.108 12.075
145 -1607 0.020 0.005 0.026 12.075
145 -1608 -0.020 0.005 -0.015 12.075
145 -1597 0.000 0.004 0.004 12.075
145 -1605 0.000 0.005 0.005 12.075
145 -1604 -0.083 0.005 -0.078 12.075
145 -1601 -0.027 0.004 -0.022 12.075
145 -1600 -0.058 0.004 -0.054 12.075
145 -1603 0.000 0.005 0.005 12.075
145 -1602 -0.020 0.005 -0.015 12.075
145 -1606 -0.009 0.004 -0.004 12.075
145 -1598 -0.082 0.003 -0.078 12.075
147 -1599 -0.167 0.000 -0.167 10.897
165 -1602 0.000 0.000 0.000 9.433
165 -1597 0.000 0.000 0.000 9.433
165 -1604 0.000 0.000 0.000 9.433
165 -1608 -0.429 0.000 -0.429 9.433
165 -1601 0.000 0.000 0.000 9.433
165 -1606 0.000 0.000 0.000 9.433
165 -1605 0.000 0.000 0.000 9.433
165 -1600 0.000 0.000 0.000 9.433
165 -1607 -0.429 0.000 -0.429 9.433
165 -1603 0.000 0.000 0.000 9.433
165 -1599 0.000 0.000 0.000 9.433
165 -1598 0.000 0.000 0.000 9.433
*
* 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/
*
* 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/