friedland-package: Making Functions Do Your Econometrics For You

Description Author(s) See Also Examples

Description

A repository of the functions and datasets I use. Many of the Applied Econ function code was inspired from Professor Roger Keener at Illinois (found here http://www.econ.uiuc.edu/~econ508/e-ta.html) while the methodologies are attributable to my classes with Professor Robert Kaufmann at Boston University.

Author(s)

Evan Friedland Maintainer: Evan Friedland <evan.friedland@gmail.com>

See Also

adf UnitRoot Asymmetry NhemShem MacKinnon aic gatelyPriceAsymm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  
  ## load package ##
    #update.packages(checkBuilt = TRUE)
    #install.packages("remotes")
    #remotes::install_github("efriedland/friedland")
    #library(friedland)
    #?friedland

  ## load data ##
  data(Asymmetry) # dataset
  data(MacKinnon) # needed for computing pvalue of the Augmented Dickey-Fuller statistic (adf)
  # package also includes data(NhemShem)

  ## turn data into time series class ##
  dat.ts <- ts(Asymmetry[,-1], start = c(2003,6), frequency = 12)

  ## choose max lag with ad hoc method ##
  floor(nrow(dat.ts)^(1/3))

  ## determine if variable stationary or nonstationary, where k is maxlag ##
  args(UnitRoot) # default
  UnitRoot(variable = dat.ts[,"Pcrude"], k = 5, trend = F)

  ## do the above process quickly across all variables in the dataset with the UnitRootApply() function ##
  UnitRootApply(dat.ts, k = 5, trend = F) # drift = T and cointvariables = 1 is the default

  ## We can decompose the Pcrude value into its vectors of its 
  ## maximum values, cumulative upward movements, and cumulative 
  ## downward movements with the gatelyPriceAsymm() function ##
  str(gatelyPriceAsymm(dat.ts[,"Pcrude"])) # output is a list class
  ## putting all the data in the same table despite not having the same start and end dates ##
  newdat.ts.list <- c(as.list(dat.ts), gatelyPriceAsymm(dat.ts[,"Pcrude"]) )
  newdat.ts <- do.call(cbind, newdat.ts.list) # will keep NA
  # do.call(ts.intersect,newdat.ts.list) ## would not keep NA row, don't worry about this

  ## double check unit roots now that we have new variables ##
  UnitRootApply(newdat.ts, k = 5, trend = F)

  ## Test for cointegration ##
  # We do a simple regression for the residual where we use the decomposed prices of crude instead
  mu <- residuals(dynlm(Pgasoline ~ Pmax + Prec + Pcut, data = newdat.ts)) # notices uses dynlm() to keep residuals in ts format, not lm()
  class(mu)
  UnitRoot(mu, k=5, trend = F, cointvariables = 4)$reason
  # the residual is stationary, there is cointegration


  # Use the buildDOLS function which does a number of steps
  ?buildDOLS
  DOLS.list <- buildDOLS(Pgasoline ~ Pmax + Prec + Pcut, data = newdat.ts)

  DOLS.list$data.names # returns the column names of the dataset you put in 

  DOLS.list$call # returns the dynlm formula used to make the DOLS

  DOLS.list$selection # returns a table showing the lags/leads and the SBC, fixed observations, for choosing the number of lags/leads to use

  DOLS.list$leadslags # returns the # of lags/leads identified for the model with the smallest SBC

  fit <- DOLS.list$model # returns the final model, where you can also find the dates used

  summary(fit)
  start(fit)
  end(fit)

  DOLS.list$robusterrors # returns the robust errors using Newey West


  # Vector Error Correction Model is as follows
  ?buildVECM
  buildVECM(Pgasoline ~ Pmax + Prec + Pcut, newdat.ts,  
       stationary.vars = ~ Utilization + Stocks) # add the stationary variables like so
  

efriedland/friedland documentation built on Feb. 9, 2021, 11:53 a.m.