Sunday, January 31, 2021

Some Important Codes in R (Applied Econometrics)

 ■ Some codes in R

Note: Dep var = Dependent Variable.

           Ind var = Independent Variable.

           Var 1 = Variable 1

           Var 2 = Variable 2

a) Taking log values

lvar1 <- log(var1, base = 10)


b) Correlation Test

#install.packages (corTest)

library (corTest)

cor.test(var1, var2)


c) Unit Roots Test (without deseaonalisation)

# install.packages(fUnitRoots)

library(fUnitRoots)


d) Testing Unit Root at Level (ADF)

adfTest (lvar1, lags = 0, type = "c")

e) Taking 1st difference

d.var1 <-diff (var1)

f) Lag selection criteria

#install.packages (vars)

library (vars)

Say, 

kk <-cbind (lvar1, lvar2, ... lvarn)

VARselect (kk) $selection

g) Co Integration  (Johannessen)

Say,

JC1 <- ca.jo (kk, type = "trace", ecdet = "none", K =3)

h) Eigen Value Stat

JC1 <- ca.jo (kk, type = "eigen", ecdet = "none", k = 3)

i) VECM (in p - 1 lags)

Say, 

model1 = VECM (data.frame (vars), lag = n, r = m, estim = "ML")

where, r = no. of co integrating relationship (will discuss later)

j) Impulse Response Function

plot (irf (model1, n.ahead=10))

for 10 periods.


To be contd...

Aditya Pokhrel 

MBA, MA Economics, MPA 

No comments:

Post a Comment

Regression Discontinuity - How to determine whether it is Sharp or Fuzzy RD ? Simplest Look.           Regression discontinuity design is ga...