wu.hausman.test: A Wu-Hausman Test for a single endogenous variable In skranz/sktools: Helpful functions used in my courses

Description

See e.g. Green (2003) Econometric Analysis for a description of the Wu-Hausman-Test

Usage

 `1` ```wu.hausman.test(y, X.exo, X.endo, Z) ```

Arguments

 `y` the vector of dependent variables `X` the matrix of explanatory variables (endogenos & exogenous) `Z` the matrix of instruments (excluded & included instruments) `endo` vector or matrix of variables that might be endogenous

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 73 74 75 76 77 78 79 80``` ```## Not run: library(sktools) # Ice cream model T = 100 beta0 = 100; beta1 = -1; beta2 = 40 s = rep(0:1, length.out=T) # Season: winter summer fluctuating eps = rnorm(T,0,2) c = runif(T,10,20) # Optimal price if the firm knows season s and u p = (beta0+beta2*s+eps - beta1*c) / (2*-beta1) # Alternatively: prices are a random markup above cost c #p = c*runif(T,1,1.1) # Compute demand q = beta0 + beta1*p+ beta2*s + eps # Matrix of instruments Z = cbind(1,c,s) # Run the Wu-Hausman test for testing endogeniety of p wu.hausman.test(y=q,X.exo=cbind(1,s),X.endo=p,Z=Z) ########################################################################################### # Run a systematic simulation study of # the Wu-Hausman Test ########################################################################################### # This function simulates and estimates a demand function and # returns the p-value of a Wu-Hausman test for endogeniety of the price sim.and.test = function() { # Ice cream model T = 100 beta0 = 100; beta1 = -1; beta2 = 40 s = rep(0:1, length.out=T) # Season: winter summer fluctuating eps = rnorm(T,0,2) c = runif(T,10,20) # Optimal price if the firm knows season s and u p = (beta0+beta2*s+eps - beta1*c) / (2*-beta1) # Alternatively: prices are a random markup above cost c p = c*runif(T,1,1.1) # Compute demand q = beta0 + beta1*p+ beta2*s + eps # Matrix of instruments Z = cbind(1,c,s) # Run the Wu-Hausman test for testing endogeniety of p wu.hausman.test(y=q,X.exo=cbind(1,s),X.endo=p,Z=Z)\$p.value } # Perform a simulation study of our implementation of the Wu-Hausman test sim = simulation.study(sim.and.test,repl=1000) # I just need to adapt the results (won't be neccessary in a # newer version of sktools) sim = as.data.frame(sim) colnames(sim)[2] = "p.value" # Show the results and draw a histogram head(sim) hist(sim\$p.value) # If the data is generated such that the Null hypothesis that # p is exogenous holds, then the p-values should be uniformly # distributed. # Use a Kolmogorov-Smirnov Test for whether p-values are uniformely distributed #ks.test(sim\$p.value,"punif",min=0,max=1) ## End(Not run) ```

skranz/sktools documentation built on May 30, 2019, 3:03 a.m.