Uploaded by wikibel123

STATA Commands

advertisement
STATA Commands
Managing Data:

























cd „destination string” – changes working directory / saves all changes in particular folder
copy “link” name to save a file
unzipfile file name
replace – replaces file with the same name in the working directory
import
delimited
rowrange (row numbet:row number) – tells stata to read only these rows
delimiters – (“”) – each number is separated by the other by something under quotation
varnames (4) – tells stata that in row 4 are the names of variables
rename old name new name
tostring – changes variable from number into string
generate
generate year = substr (data,1,4) / generate month = substr (data,5,2) – start from position 5
and read 2 numbers
destring
generate newdate = ym(year, month) – ym combines year and month
format newdate %tm changes date to normal format
drop
order date, first
getsymbols ticker, yahoo fd(1) fm(1) fy(1981) ld(30) lm(11) ly(2020) frequency(m)
price(adjclose) clear
clear at the end removes existing data from variables tab before downloading
drop name* //drops everything with the same beginning
merge 1:1 //merges overlapping data
merge 1:1 date using ff.dta
keep if _merge==3 //(DOUBLE EQUAL SYMBOL)
tsset date, m // time series set, month
Capm Model: we work with returns






generate lnapple = ln(apple) // logarithm of apple adjclose price
generate rapple = 100*(lnapple – L.lnapple) // generate return of apple in percentage.
L. in time series is t-1
describe
generate mkt = mktrf+rf // generates market return = premium market return + risk free
return
set scheme s1color // changes the appearance of a graph
twoway (line mkt rapple date, sort) // generates a graph



histogram rapple, normal normopts(lcolor(red)) kdensity name(apple) // plots a histogram
with normal distribution and additional options, kdensity plots distribution of the data saves
under name apple
graph combine apple market
summarize rapple mkt
Estimation of the capm model means finding alfa and beta that characterise the relationship
between dependent variable and independent variable (relationship between return of an
asset and market)


generate rirf = rapple – rf //excess return of apple = return of apple – risk free return
regress rirf (dependant variable) mktrf (independent)
R squared – represents goodness of fit of the model. Explains how good is the model in
explaining the variability of the dependent variable. Lays between (0-1)
F-test – overall significance test – compares a model with only a constant and a model with a
set of regressors// shows if the set of regressors is useful in explaining the variability of the
dependent variable
IN LECTURE 1 LAST 10 MINUTES – THE REGRESSION EXPLAINED
CLASS 2 MULTIPLE LINEAR REGRESSION MODEL
Linear regression model is the most used model in econometrics
It models the conditional mean of a response variable y as a function of k independent
variables
FAMA AND FRENCH MODEL – extension of CAPM


test ersandp = 1 // tests if the coefficient associated to ersandp is equal to 1
regress dependent variable independent variable // multiple linear regression model
For 3FF sbm and hml regressors are included // explained in slides for lecture 2
NULL test, alpha =0, and alternative alpha =/ 0
Significance test
t-statistic compare absolute value of t to its critical value
IF |t| > tcv the test is significant and you reject null
If |t| < tcv he test is not significant and you do not reject null hypothesis
Critical values are tested at 1% 5% and 10%
Download