stata代写-ECON 5069
时间:2022-02-22
Adam Smith Business School
UNIVERSITY OF GLASGOW
Empirical Asset Pricing, ECON 5069
Lab 2: Black-Jensen-Scholes (1972)
Pre-reading: Black, F., M. Jensen and M. Scholes, 1972, “The capital asset pricing model: some
empirical tests”, Studies in the Theory of Capital Markets, M. Jensen, Ed., New York, Praeger.
1 Data
Monthly stock prices on 85 UK companies over the period of Jan 1985. – Dec. 2006 (264 months).
Thus total number of observations is 22,440. Following variables contained in our dataset. We use
FTSE100 index as proxy for the market portfolio and 3-month Treasury Bill for the risk-free rate.
Followings are variable definitions:
• nid: individual index
• tid: date index (1985m1 - 2006m12)
• yid: year index (1985-2006)
• mid: month index (1-12)
• entityname: company name
• keyindex: key index
• sp: UK company stock price
• ftse100: FTSE100 index
• tb3m: 3-month Treasury Bill rate
• size: company size
2 Portfolio Construction
1. Generate excess returns:
rit = Rit −Rft, Rit = lnPit − lnPi,t−1 (1)
rmt = Rmt −Rft, Rmt = lnPmt − lnPm,t−1, (2)
where Pit denotes a stock price for company i and Pmt the price of the market portfolio.
2. Start with 1985-1989 (60 months)
Dr. Minjoo Kim [1] Empirical Asset Pricing, ECON5069
Adam Smith Business School
Table 1: Time-series test of 10 portfolios
Portfolio
1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th
βˆp 1.3645 1.0339 0.9658 0.9574 0.8685 0.8692 0.8843 0.7608 0.5722 0.6181
αˆp -0.0012 -0.0011 -0.0004 -0.0009 -0.0026 -0.0003 0.0008 0.0003 0.0017 -0.0015
t (αˆp) -0.2626 -0.3374 -0.1497 -0.3038 -0.8396 -0.1072 0.2741 0.1189 0.6269 -0.4960
r¯p 0.0005 0.0002 0.0007 0.0003 -0.0016 0.0008 0.0019 0.0013 0.0024 -0.0007
σ (rp) 0.0850 0.0613 0.0579 0.0560 0.0571 0.0539 0.0548 0.0495 0.0457 0.0497
(a) Estimate beta for each company by applying time-series regression:
rit = αi + βirmt + it. (3)
(b) Rank stocks by estimated betas and form portfolio, 1st – 10th.
(c) Calculate monthly returns for each of 12 months in 1990 for 10 portfolios:
rp = N−1p
Np∑
i=1
ri, p = 1, . . . , 10, (4)
Np is the number of stocks within the portfolio.
3. Recalculate the portfolio returns for 1991,...,2006 by repeating (a)-(c). Then we have 12
monthly returns for 17 years (204 months).
3 Time-series Test
1. For the full sample, calculate alpha for each portfolio by estimating
rpt = αp + βprmt + pt, p = 1, . . . , 10. (5)
2. Then test H0 : αp = 0 for each portfolio.
3. From Table 1, t-statistic has not been rejected for all portfolios.
4 Cross-sectional Test
1. Calculate mean excess portfolio returns, r¯p for each of the 10 portfolios.
2. Regress r¯p against βˆp obtained in the previous time-series test:
r¯p = λ0 + λ1βˆp + ξp. (6)
Dr. Minjoo Kim [2] Empirical Asset Pricing, ECON5069
Adam Smith Business School
Table 2: Cross-sectional test
Regression 1 denotes OLS with normal standard error while Regression 2 with bias-corrected
standard error. (·) stands for the standard error of estimate. * indicates that the estimate is
significant at 10% level.
Regression 1 Regression 2
γˆ0 0.0013 0.0013
(0.0017) (0.0019)
γˆ1 -0.0009 -0.0009
(0.0013) (0.0018)
r¯m 0.0068
H0 : γ0 = 0, F-test [p-value] 0.65 [0.4433] 0.49 [0.5021]
H0 : γ1 = r¯m, F-test [p-value] 1.32 [0.2846] 1.29 [0.2889]
3. Then test
H0 : λ0 = 0 (7)
H0 : λ1 = r¯m (8)
4. From Table 2, none of above hypotheses have been rejected. γˆ0 is -2.4% which is actually
much deviated from 0%. γˆ1 is 3.3% which is also much deviated from r¯m, 0.7%. Why have
been they rejected in spite of large deviations from the targets?
5 STATA Program Guide
• Stata batch file ‘lab2.do’ contains all necessary commands to perform Black-Jensen-Scholes
test.
• Key Stata commands: MATA function, forvalues, collapse. Please type help ‘command’ at
the command window of Stata to find detailed description.
4 Clear all in memory and tell STATA to pause for more messages:
clear all
set more off
4 MATA function starts with mata: and ends with end. void defines a function name which
requires input. real scalar (colvec, rowvec, matrix) defines the type of the variable which will be
used in the MATA function: real scalar – scalar, real colvec – column vector, real rowvec – row
vector and real matrix – matrix. Ideal location for the MATA function will be after clear and set
commands or at the end of the STATA code.
mata:
viod function_name(string scalar variable_name) {
Dr. Minjoo Kim [3] Empirical Asset Pricing, ECON5069
Adam Smith Business School
Figure 1: Average monthly excess return versus systemic risk
real scalar
real colvec
real rowvec
real matrix
...
...
...
}
end
4 Create log file: If the log file already exists, then it will be replaced with the update. Type help
log in the STATA command window for the detail information:
log using “log_file_name.smcl”, replace
4 Load dataset and declare a monthly panel data. The panel data declaration makes the operation
of variable easier. Type help use and help tsset in the STATA command window for the detail
information:
use “ukstock.dta”, clear
tsset nid tid, monthly
4 Generate the logarithm of stock prices using STATA command generate and a natural log
function ln. We can also use ge, the abbreviation of generate:
Dr. Minjoo Kim [4] Empirical Asset Pricing, ECON5069
Adam Smith Business School
generate lsp = ln(sp)
generate lftse = ln(ftse)
4 Generate the first-difference of the logarithms of stock prices using a difference operator d.
generate ri = d.lsp
generate rm = d.lftse
4 Generate a monthly risk-free rate by dividing annualized percentage 3-month treasury bill rate
by 12× 100.
generate rf = tb3m/(12*100)
4 Delete two variables using STATA command drop:
drop lsp lftse
4 Generate excess returns:
generate ui = ri-rf
generate um = rm-rf
4 Generate empty variables using .:
generate beta = .
generate pid = .
4 Construct portfolio from 1990 to 2006 by looping which repeats a same procedure using STATA
command forvalues which has the following structure:
forvalues i = 0/15 {
commands
}
This looping repeats commands from 0 to 15 in step of 1. STATA macro ‘i’ refers 0 at the first
iteration, 1 at the second iteration and so on. Commands include followings:
Display a period from 1985+‘i’ to 1989+‘i’ using STATA command display:
display "from " 1985+‘i’ " to " 1989+‘i’
Looping following commands for 85 companies using forvalues:
forvalues j = 1/85 {
quietly regress ui um if (yid >= 1985+‘i’) & (yid <= 1989+‘i’) & (nid == ‘j’)
matrix bj = e(b)
matrix b = (nullmat(b)\bj[1,1])
quietly replace beta = bj[1,1] if (yid == 1990+‘i’) & (nid == ‘j’)
}
where STATA macro ‘j’ refers 1 at the first iteration, 2 at the second iteration and so on. In the
looping, we first perform regression for the period of 1985+‘i’ – 1989+‘i’ and the firm ‘j’ using
STATA command regress. if restricts the period and the firm. We can also use STATA command
reg, the abbreviation of regress. STATA command quietly performs command but suppress terminal
output. Second, we save the vector of the estimates, e(b), in the matrix using STATA command
Dr. Minjoo Kim [5] Empirical Asset Pricing, ECON5069
Adam Smith Business School
matrix. The vector of the estimates includes intercept and slope coefficients. We can also check
the dimension of the estimates vector by typing ereturn list after the regression. Then we stack
the estimates of beta coefficient in the matrix b. nullmat creates a matrix b if matrix name b does
not exist. Finally we replace empty elements in variable beta with beta coefficients for the year of
1990+‘i’ and the firm ‘j’ using STATA command replace.
We generate a matrix which contains 9 quantiles of beta such as 10%, 20%, ..., 90% by calling
the MATA function beta_quant( ). As the input of the function, we use matrix b generated in the
sub-looping. The output will be saved in matrix bq:
mata: beta_quant("b")
Then we replace empty elements in variable pid with portfolio indicator for the year of 1990+‘i’
and the firm ‘j’ using STATA command replace. For example, portfolio index 10 indicates the
lowest quantile group while 1 the highest quantile group. Matrix bq contains 9 quantiles of beta
coefficiens.
qui replace pid = 10 if (beta < bq[1,1]) & (yid == 1990+‘i’)
qui replace pid = 9 if (beta >= bq[1,1]) & (beta < bq[2,1]) & (yid == 1990+‘i’)
qui replace pid = 8 if (beta >= bq[2,1]) & (beta < bq[3,1]) & (yid == 1990+‘i’)
qui replace pid = 7 if (beta >= bq[3,1]) & (beta < bq[4,1]) & (yid == 1990+‘i’)
qui replace pid = 6 if (beta >= bq[4,1]) & (beta < bq[5,1]) & (yid == 1990+‘i’)
qui replace pid = 5 if (beta >= bq[5,1]) & (beta < bq[6,1]) & (yid == 1990+‘i’)
qui replace pid = 4 if (beta >= bq[6,1]) & (beta < bq[7,1]) & (yid == 1990+‘i’)
qui replace pid = 3 if (beta >= bq[7,1]) & (beta < bq[8,1]) & (yid == 1990+‘i’)
qui replace pid = 2 if (beta >= bq[8,1]) & (beta < bq[9,1]) & (yid == 1990+‘i’)
qui replace pid = 1 if (beta >= bq[9,1]) & (yid == 1990+‘i’) // P10: beta(90%) <= beta
Then we drop matrix b and bq using STATA command drop:
matrix drop b bq
4 Drop observations if portfolio id is not allocated in the variable pid using STATA command
drop:
drop if pid == .
4 Create the averages of variables which have been conditioned by pid and tid using STATA
command collapse. Type help collapse in the STATA command window for detail information.
collapse (mean) ri rm rf, by(pid tid)
where pid, tid, ri, rm and rf will be kept while other variables have been deleted. Now ri is the
portfolio return.
4 Declare a monthly panel dataset by pid and tid
tsset pid tid, monthly
4 Rename ri by rp using STATA command rename:
rename ri rp
Dr. Minjoo Kim [6] Empirical Asset Pricing, ECON5069
Adam Smith Business School
4 Generate the excess returns of portfolio and market portfolio:
generate up = rp-rf
generate um = rm-rf
4 Generate the empty variables of beta estimates, alpha estimates, standard error of alpha esti-
mates, average of monthly excess return and standard deviation of monthly excess return:
generate beta = .
generate alpha = .
generate talpha = .
generate mup = .
generate sup = .
4 Estimate SCL for each portfolio using STATA command forvalues:
forvalues i = 1/10 {
commands
}
This looping repeats commands from portfolio 1 to 10 in step of 1. STATA macro ‘i’ refers 1 at the
first iteration, 2 at the second iteration and so on. Commands include followings: First perform the
time-series regression of the portfolio ‘i’ using STATA command regress. Then save the estimates
of coefficients and the standard errors in matrix:
quietly regress up um if (pid == ‘i’)
matrix bi = e(b)
matrix si = vecdiag(e(V))
matrix si = sqrt(si[1,2])
Replace empty elements of beta, alpha and talpha by estimates using STATA command replace.
The slope coefficient has been saved in the first column and the intercept in the second column:
quietly replace beta = bi[1,1] if (pid == ‘i’)
quietly replace alpha = bi[1,2] if (pid == ‘i’)
quietly replace talpha = bi[1,2]/si[1,1] if (pid == ‘i’)
Obtain descriptive statistics for the excess return of the portfolio ‘i’ using STATA command sum-
mmarize. Then replace empty elements of mup and sup by the mean of excess return and the
standard deviation of excess returns which have been saved in r(mean) and r(sd) by summarize
command.
quietly sum up if (pid == ‘i’)
quietly replace mup = r(mean) if (pid == ‘i’)
quietly replace sup = r(sd) if (pid == ‘i’)
Notice that STATA command quietly perform command but suppress terminal output.
4 Create average variable which has been conditioned by pid using STATA command collapse.
Created variables will be used for tesing SML:
collapse (mean) beta alpha talpha mup sup rp rm rf, by(pid)
Dr. Minjoo Kim [7] Empirical Asset Pricing, ECON5069
Adam Smith Business School
where pid, beta, alpha, talpha, mup, sup, rp, rm and rf are kept while other variables have been
deleted.
4 Generate excess portfolio retun and excess market portfolio return:
generate up = rp-rf
generate um = rm-rf
4 Obtain the descriptive statistics of the excess market portfolio return.
quietly summarize um
4 Define scalar 0 as the theoretical value of alpha and scalar r(mean) as the theoretical value of
market premium using STATA scalar command:
scalar r0 = 0
scalar r1 = r(mean)
4 Display the results of time-series test using STATA command list:
list beta alpha talpha mup sup
4 Perfom cross-sectional regression and test H0: alpha = 0 and H0: beta = market premium using
STATA command test:
regress up beta
test _cons = r0
test beta = r1
4 Perfom the same test procedure using bias correction option vce(hc2) for the robust variance
calculation in the regression. Type help regress and look at vce(hc2) option for detail information:
regress up beta, vce(hc2)
test _cons = r0
test beta = r1
4 Plotting beta and average monthly excess returns using STATA command twoway and scatter
option with line fit option lfit. Type help twoway and look at scatter and lfit for detail information:
twoway (scatter up beta) (lfit up beta)
4 Clear MATA in memory and close log:
mata
mata clear
end
log close
Dr. Minjoo Kim [8] Empirical Asset Pricing, ECON5069