Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Useful R Commands for Econometrics
We suppose the packages car and |lmtest| to be loaded. If other packages are needed there are denoted by prefix to the
command (e. g. by XLConnect::).
1 Data Import and Manipulation
from XLS(X)
from CSV (decimal comma, semicolon separated)
from CSV (decimal point, comma separated)
from generic text file
attaching dataset
detaching dataset
list of variables
accessing a variable
XLConnect::readWorksheetFromFile("datafile.xlsx", "worksheet")
read.csv2("datafile.csv")
read.csv("datafile.csv")
read.table("datafile.txt", ...)
attach(dataset)
detach(dataset)
names(dataset)
dataset$variable
Descriptive Statistics
sample size
mean
sample variance
sample standard deviation
length(variable)
mean(variable)
var(variable)
sd(variable
2 Simple and Multiple Linear Regression
define linear model
summary of the model
what can be extracted
coefficients
(individual)
fitted values
residuals
R2
prediction
XY plot
regression line
lm(y~x, data=dataset)
summary(model)
names(model)
names(summary(model))
model$coefficients
coefficients(model)
model$coefficients["x"]
model$fitted.values
model$residuals
summary(model)$r.squared
predict(model, data.frame(x=c(30, 40)))
plot(y~x)
abline(model)
3 Statistical Inference
(residual) standard error of the regression
standard error of an estimate
t-ratio
two-sided p-value
confidence interval
SSR (residual sum of squares)
F (linear restriction) test
overall F statistics
summary(model)$sigma
summary(model)$coefficients["variable",
summary(model)$coefficients["variable",
summary(model)$coefficients["variable",
summary(model)$coefficients["variable",
confint(model)
confint(model, level=0.99)
deviance(model)
anova(submodel, model)
summary(model)$fstatistic
"Std. Error"]
"t value"]
"Pr(>|t|)"]
4]
4 Asymptotics
subset of data (first 400 observations)
LM χ2 test
dataset[1:400,]
lht(model, c("x1 = 0", "x2 = 0"), test="Chisq")
5 Further Issues and Binary Variables
model with quadratics
model with interactions
z-ratios (standardized values)
confidence interval for prediction
prediction interval
define binary variable (logical AND)
(logical OR)
lm(y~x1+I(x2^2), data=dataset)
lm(y~x1+x2+x1:x2, data=dataset)
scale(x)
predict(model, newdata, interval="confidence")
predict(model, newdata, interval="prediction")
x3 <- as.numeric(x1==1 & x2==0)
x4 <- as.numeric(x5>=0 | x6<10)
6 Heteroskedasticity
heteroskedasticity robust (White) std. errors
heteroskedasticity robust (Wald) F test
Breusch-Pagan test for heteroskedasticity
weighted LS (heteroskedasticity proportional to x)
coeftest(model, vcov.=hccm(model,"hc0"))
waldtest(submodel, model, vcov=hccm(model,"hc0"))
bptest(model)
lm(y~x,weights=1/x)