class: center, middle, inverse, title-slide .title[ # Estimation of linear panel data models using GMM ] .author[ ### Gustavo A. García
ggarci24@eafit.edu.co
] .date[ ###
Econometría avanzada II
PhD/Maestría en Economía
Universidad EAFIT
] --- <style> .notbold{ font-weight:normal } body { text-align: justify; } h1{ margin-top: -1px; margin-bottom: -3px; } .small-code pre{ margin-bottom: -10px; } .medium-code pre{ margin-bottom: 2px; } </style> <font size = "5"> <br> <br> <br> <br> <br> Link slides en formato [html](https://gusgarciacruz.github.io/EconometriaAvanzadaII/ModelosPanelGMM/ModelosPanelGMM.html) Link slides en formato [PDF](https://gusgarciacruz.github.io/EconometriaAvanzadaII/ModelosPanelGMM/ModelosPanelGMM.pdf) --- # <span style="font-size:80%">Outline</span> - <span style="font-size:150%">[<span style="color:black">Motivation](#motivation)</span> <br> <br> - <span style="font-size:150%">[<span style="color:black">General model](#gmodel)</span> <br> <br> - <span style="font-size:150%">[<span style="color:black">What is GMM?](#GMM)</span> <br> <br> - <span style="font-size:150%">[<span style="color:black">GMM and instrumental variables](#GMMIV)</span> <br> <br> - <span style="font-size:150%">[<span style="color:black">System two-stage least squares estimator](#TSLS)</span> <br> <br> - <span style="font-size:150%">[<span style="color:black">Optimal weight matrix](#OWM)</span><br> <br> - <span style="font-size:150%">[<span style="color:black">Application using R](#R)</span> --- # <span style="font-size:80%">Lecturas</span> - <span style="font-size:150%">Wooldridge, J. (2010). *Econometric Analysis of Cross Section and Panel Data*. 2a edición. MA: MIT Press. <span style="color:blue">Cap 11.1 <br> <br> --- name: motivation # <span style="font-size:80%">Motivation</span> <font size = "5"> - Use of panel data regression methods has become increasingly popular as the availability of longitudinal data sets has grown - Panel data contains repeated time-series observations (T) for a large number (N) of cross-sectional units (e.g., individuals, households, or firms) - An important advantage of using such data is that they allow researchers to control for unobservable heterogeneity, that is, <span style="color:blue">systematic differences across cross-sectional units</span> - <span style="color:blue">Omitting this unobservable heterogeneity in regressions on aggregated time-series and pure cross-section data, the statistical inferences could be seriously biased --- # <span style="font-size:80%">Motivation</span> <font size = "5"> - When panel data are available, <span style="color:blue">error-components models</span> can be used to control for these individual differences `\(\Longrightarrow\)` these model assumes that the stochastic error term has two components: - a time-invariant individual effect which captures the unobservable individual heterogeneity - a usual random noise term - Some explanatory variables (e.g., years of schooling in the earnings equation) are likely to be correlated with the individual effects (e.g., unobservable talent or IQ). A simple treatment to this problem is the <span style="color:blue">within estimator</span> which is equivalent to least squares after transformation of the data to deviations from means --- # <span style="font-size:80%">Motivation</span> <font size = "5"> Unfortunately, the within method has two serious defects: <p style="margin-bottom: -1em"> - the within transformation of a model <span style="color:blue">wipes out time invariant regressors as well as the individual effect</span>, so that it is not possible to estimate the effects of time-invariant regressors on the dependent variable <p style="margin-bottom: -1em"> - consistency of the within estimator requires that <span style="color:blue">all the regressors in a given model be strictly exogenous with respect to the random noise</span> (e.g. dynamic models including lagged dependent variables as regressors) <span style="color:blue">In response to these problems, a number of studies have developed alternative GMM estimation methods</span>. There are several different types of models: <p style="margin-bottom: -1em"> - the linear regression model with strictly or weakly exogenous regressors - the simultaneous regression model - the dynamic linear model containing a lagged dependent variable as a regressor In each case, different assumptions about the exogeneity of the explanatory variables generate different sets of moment conditions that can be used in estimation --- name: gmodel # <span style="font-size:80%">General model</span> <font size = "5"> We have the following commom model: `$$y_{it} = \textbf{x}_{it}\boldsymbol\beta + \upsilon_{it}; \upsilon_{it} = c_i + u_{it} \tag{1}$$` `\(i=1,...,N\)` represents the cross-sectional unit (individual) and `\(t=1,...,T\)` indexes time. `\(y_{it}\)` is the dependent variables; `\(\textbf{x}_{it}=(\textbf{x}_{i1}, \textbf{x}_{i2},...,\textbf{x}_{iT})\)` is a `\(1\)` x `\(K\)` vector of explanatory variables and `\(\boldsymbol\beta\)` is a `\(K\)` x `\(1\)` vector of unknown parameters Writing the model (1) for all `\(T\)` time periods as `$$\textbf{y}_i = \textbf{X}_i \boldsymbol\beta + \textbf{v}_i \tag{2}$$` donde `\(\textbf{v}_i = c_i \textbf{j}_T + \textbf{u}_i\)` <p style="margin-bottom: -1em"> `\(\textbf{y}_i=(y_{i1},y_{i2},...,y_{iT})'\)` is a `\(T\)` x `\(1\)` vector<br> `\(\textbf{X}_i=(\textbf{x}'_{i1},\textbf{x}'_{i2},...,\textbf{x}'_{iT})'\)` is a `\(T\)` x `\(K\)` matrix<br> `\(\textbf{v}_i=(\upsilon_{i1}, \upsilon_{i2},...,\upsilon_{iT})'\)` is a `\(T\)` x `\(1\)` vector<br> `\(\textbf{u}_i=(u_{i1}, u_{i2},...,u_{iT})'\)` is a `\(T\)` x `\(1\)` vector<br> `\(\textbf{j}_T=(1,1,...,1)'\)` is the `\(T\)` x `\(1\)` vector of ones --- # <span style="font-size:80%">General model</span> <font size = "5"> There are two well-known special cases of this model: the traditional <span style="color:blue">random effects</span> and <span style="color:blue">fixed effects</span> models. Both of these models assume that the <span style="color:blue">regressors `\(\textbf{X}_i\)` are strictly exogenous with respect to the random noise `\(u_{it}\)`</span> (i.e., `\(E(\textbf{x}_{it}'u_{it}) = \textbf{0}\)` for any `\(t\)` and `\(s\)`) <span style="color:blue">The random effects model (Balastra and Nerlove, 1966)</span> This model treats the individual effects are as random unobservable which are uncorrelated with all of the regressors Under this assumption, the parameter vector `\(\boldsymbol\beta\)` can be consistently and efficiently estimated by FGLS of the following form: `$$\boldsymbol\beta_{RE} = \left(\sum_{i=1}^{N}\textbf{X}_{i}'\widehat{\boldsymbol\Omega}^{-1}\textbf{X}_{i}\right)^{-1}\left(\sum_{i=1}^{N}\textbf{X}_{i}'\widehat{\boldsymbol\Omega}^{-1}\textbf{y}_{i}\right) \tag{3}$$` where `\(\widehat{\boldsymbol\Omega} = \widehat{\sigma}_{u}^{2}\textbf{I}_T + \widehat{\sigma}_{c}^{2}\textbf{j}_T\textbf{j}_{T}'\)` is the variance matrix estimated of `\(\textbf{v}_i\)` --- # <span style="font-size:80%">General model</span> <spam style="font-size:120%"> <span style="color:blue">The fixed effects model</span><br> When we treat the `\(c_i\)` as nuisance parameters, the model reduces to the traditional fixed effects model. A simple treatment of the fixed effects model is to remove the effects by the (within) transformation of the model to deviations from individual means: `$$y_{it} - \overline{y}_i = (\textbf{x}_{it} - \overline{\textbf{x}}_i)\boldsymbol\beta + u_{it} - \overline{u}_i$$` or `$$\ddot{y}_{it}=\ddot{\textbf{x}}_{it}\boldsymbol\beta + \ddot{u}_{it} \tag{4}$$` Writing equation (4) for all time periods as `$$\ddot{\textbf{y}}_{i}=\ddot{\textbf{X}}_{i}\boldsymbol\beta + \ddot{\textbf{u}}_{i}$$` or `$$\textbf{Q}_T \textbf{y}_i = \textbf{Q}_T \textbf{X}_i \boldsymbol\beta + \textbf{Q}_T \textbf{u}_i \tag{5}$$` where `\(\textbf{Q}_T = \textbf{I}_T - \textbf{j}_t(\textbf{j}_t'\textbf{j}_t)^{-1}\textbf{j}_t'\)` is a <span style="color:blue">time-demeaning matrix</span> which is a `\(T\)` x `\(T\)` symmetric, idempotent matrix --- # <span style="font-size:80%">General model</span> <font size = "5"> Least squares on (5) yields the familiar within estimator: `$$\boldsymbol\beta_{FE} = \left(\sum_{i=1}^{N}\ddot{\textbf{X}}_{i}'\ddot{\textbf{X}}_{i}\right)^{-1}\left(\sum_{i=1}^{N}\ddot{\textbf{X}}_{i}'\ddot{\textbf{y}}_{i}\right) \tag{6}$$` - Although the fixed effects model views the effects `\(c_i\)` as nuisance parameters rather than random variables, the fixed effects treatment (within estimation) is not inconsistent with the random effects assumption - Mundlak (1978) considers an alternative random effects model in which the effects `\(c_i\)` are allowed to be correlated with all of the regressors `\(\textbf{x}_{i1},...,\textbf{x}_{iT}\)`. For this model, Mundlak shows that the within estimator is an efficient GLS estimator - <span style="color:blue">This finding implies that the core difference between the random and fixed effects models is not whether the effects are literally random or nuisance parameters, but whether the effects are correlated or uncorrelated with the regressors --- name: GMM # <span style="font-size:80%">What is GMM?</span> <font size = "5"> - The generalize method of moments (GMM) is a general framework for deriving estimators - GMM estimators use assumptions about the moments of the random variables to derive an objective function - The assumed moments of the random variables provide population moment conditions - The data are used to compute the analogous sample moment conditions - The parameters estimates are obtained by finding the parameters that make the sample moment conditions as true as possible. This step is implemented by minimizing an objective function - GMM produces estimators using few assumptions, but is less efficient than, for example, ML that uses the entire distribution while GMM only uses specified moments --- # <span style="font-size:80%">What is GMM?</span> <font size = "5"> <span style="color:blue">What is generalized about GMM? - In the method of moments (MM), we have the same number of sample moment conditions as we have parameters - In the generalized method of moments (GMM), we have more sample moment conditions than we have parameters --- # <span style="font-size:80%">What is GMM?</span> <spam style="font-size:105%"> <span style="color:blue">OLS is a MM estimator</span> <p style="margin-bottom: -1em"> We know that OLS estimates the parameters of the conditional expectation of (in cross sectional data) `\(y_i = \textbf{x}_i \boldsymbol\beta + \epsilon_i\)` under the assumption that `\(E(\epsilon|\textbf{x}_i)=\textbf{0}\)` Standard probability theory implies that `$$E(\epsilon|\textbf{x}_i)=\textbf{0} \Longrightarrow E(\textbf{x}'_i\epsilon)=\textbf{0}$$` So that the population moment conditions for OLS are `$$E[\textbf{x}'_i(y_i - \textbf{x}_i \boldsymbol\beta)]=\textbf{0}$$` The corresponding sample moment conditions are `$$N^{-1}\sum_{i=1}^N \textbf{x}'_i(y_i - \textbf{x}_i \widehat{\boldsymbol\beta})=\textbf{0}$$` Solving for `\(\widehat{\boldsymbol\beta}\)` yields `$$\widehat{\boldsymbol\beta}_{OLS}=\left(\sum_{i=1}^N \textbf{x}'_i\textbf{x}_i\right)^{-1} \left(\sum_{i=1}^N \textbf{x}'_iy_i\right)$$` --- # <span style="font-size:80%">What is GMM?</span> <font size = "5"> <span style="color:blue">OLS is a MM estimator</span> <p style="margin-bottom: -1em"> - The MM only works when the number of moment conditions equals the number of parameters to estimate - If there are more moment conditions than parameters, the system of equations is algebraically over identified and cannot be solved - GMM estimators choose the estimates that minimize a quadratic form of the moment conditions - GMM gets as close to solving the over-identified system as possible - GMM reduces to MM when the number of parameters equals the number of moment conditions --- # <span style="font-size:80%">What is GMM?</span> <spam style="font-size:120%"> <span style="color:blue">Definition of GMM estimator</span> <p style="margin-bottom: -1em"> - Our research question implies `\(q\)` population moment conditions `$$E[\textbf{m}(\textbf{w}_i,\boldsymbol\theta)]=\textbf{0}$$` `\(\textbf{m}\)` is `\(q\)` x `\(1\)` vector of functions whose expected values are zero in the population<br> `\(\textbf{w}_i\)` is the data on person `\(i\)`<br> `\(\boldsymbol\theta\)` is `\(K\)` x `\(1\)` vector of parameters, `\(K\leq q\)` - The sample moments that correspond to the population moments are `$$\overline{\textbf{m}}(\widehat{\boldsymbol\theta})=N^{-1}\sum_{i=1}^{N}\textbf{m}(\textbf{w}_i,\widehat{\boldsymbol\theta})$$` - When `\(K<q\)`, the GMM chooses the parameters that are as close as possible to solving the over-identified system of moment conditions `$$\widehat{\boldsymbol\theta}_{\text{GMM}} = \text{arg min}_{\widehat{\boldsymbol\theta}} \text{ }\overline{\textbf{m}}(\widehat{\boldsymbol\theta})'\textbf{W}\overline{\textbf{m}}(\widehat{\boldsymbol\theta})$$` --- name: GMMIV # <span style="font-size:80%">GMM and instrumental variables</span> <font size = "5"> - We now examine GMM and other related instrumental variables estimators for equation (2) - Our main focus is a general treatment of given moment conditions, so that we do not make any specific exogeneity assumption regarding the regressors `\(\textbf{X}_i\)` - We simply begin by assuming that there is a set of `\(T\)` x `\(L\)` instruments `\(\textbf{Z}_i\)`, which satisfies the following <span style="color:blue">orthogonality condition</span> and <span style="color:blue">rank condition</spab> `$$E(\textbf{Z}'_i\textbf{v}_i) = \textbf{0} \tag{7}$$` `$$\text{rank } E(\textbf{Z}'_i\textbf{X}_i) = K \tag{8}$$` Since `\(E(\textbf{Z}'_i\textbf{X}_i)\)` is an `\(L\)` x `\(K\)` matrix, rank assumption requires the columns of this matrix to be linearly independent. Necessary for the rank condition is the <span style="color:blue">order condition: `\(L\geq K\)` --- # <span style="font-size:80%">GMM and instrumental variables</span> <font size = "5"> - The orthogonality conditions suggest an estimation strategy - Under assumptions of orthogonality and rank, `\(\boldsymbol\beta\)` is the <span style="color:blue">unique</span> `\(K\)` x `\(1\)` vector solving the linear set population moment conditions `$$E[\textbf{Z}'_i(\textbf{y}_i-\textbf{X}_i\boldsymbol\beta)]=\textbf{0} \tag{9}$$` - Because sample averages are consistent estimators of population moments, the analogy principle applied to condition (9) suggests choosing the estimator `\(\widehat{\boldsymbol\beta}\)` to solve `$$N^{-1}\sum_{i=1}^N \textbf{Z}'_i(\textbf{y}_i-\textbf{X}_i\widehat{\boldsymbol\beta})=\textbf{0} \tag{10}$$` Equation (10) is a set of `\(L\)` linear equations in the `\(K\)` unknowns in `\(\widehat{\boldsymbol\beta}\)` --- # <span style="font-size:80%">GMM and instrumental variables</span> <font size = "5"> Considers the following cases in the solution of the system: <span style="color:blue"> `\(L=K\)`</span>: there are exactly enough IVs for the explanatory variables (system exactly identified). Then we can solve for `\(\widehat{\boldsymbol\beta}\)` as `$$\widehat{\boldsymbol\beta} = \left(N^{-1}\sum_{i=1}^N\textbf{Z}'_i\textbf{X}_i\right)^{-1}\left(N^{-1}\sum_{i=1}^N\textbf{Z}'_i\textbf{y}_i\right) \tag{11}$$` or `$$\widehat{\boldsymbol\beta} = \left(\textbf{Z}'\textbf{X}\right)^{-1}\left(\textbf{Z}'\textbf{Y}\right)$$` `\(\textbf{Z}\)` is a `\(NT\)` x `\(L\)` matrix; `\(\textbf{X}\)` is a `\(NT\)` x `\(K\)` matrix; and `\(\textbf{Y}\)` is a `\(NT\)` x `\(1\)` vector Equation (11) is called the <span style="color:blue">system IV (SIV) estimator</span> --- # <span style="font-size:80%">GMM and instrumental variables</span> <font size = "5"> <span style="color:blue"> `\(L>K\)`</span>: more columns in IV matrix `\(\textbf{Z}_i\)` than we need for identification (system overidentified). Choosing `\(\widehat{\boldsymbol\beta}\)` is more complicated and the equation will not have a solution Instead, we choose `\(\widehat{\boldsymbol\beta}\)` to make the vector in equation (10) as "small" as possible in the sample. One possibility is to <span style="color:blue">minimize the squared Euclidean length of the `\(L\)` x `\(1\)` vector in equation (10)</span> This approach suggest choosing `\(\widehat{\boldsymbol\beta}\)` to make as small as possible the following expression (dropping `\(N^{-1}\)` in (10)): `$$\left[\sum_{i=1}^N \textbf{Z}'_i(\textbf{y}_i-\textbf{X}_i\widehat{\boldsymbol\beta})\right]'\left[\sum_{i=1}^N \textbf{Z}'_i(\textbf{y}_i-\textbf{X}_i\widehat{\boldsymbol\beta})\right]$$` <span style="color:blue">While this method produces a consistent estimator under orthogonality and rank assumptions, it rarely produces the best estimator --- # <span style="font-size:80%">GMM and instrumental variables</span> <font size = "5"> A more general class of estimator is obtained by using a <span style="color:blue">weighting matrix</span> in the quadratic form. Let `\(\widehat{\textbf{W}}\)` be an `\(L\)` x `\(L\)` symmetric, positive semidefinite matrix, where the "hat" is included to emphasize that `\(\widehat{\textbf{W}}\)` is a estimator A <span style="color:blue">generalized method of moments (GMM) estimator</span> of `\(\boldsymbol\beta\)` is a vector `\(\widehat{\boldsymbol\beta}\)` that solves the problem `$$\min_{\textbf{b}}\left[\sum_{i=1}^N \textbf{Z}'_i(\textbf{y}_i-\textbf{X}_i\textbf{b})\right]'\widehat{\textbf{W}}\left[\sum_{i=1}^N \textbf{Z}'_i(\textbf{y}_i-\textbf{X}_i\textbf{b})\right] \tag{12}$$` The unique solution to the latter expression is `$$\widehat{\boldsymbol\beta} = (\textbf{X}'\textbf{Z}\widehat{\textbf{W}}\textbf{Z}'\textbf{X})^{-1}(\textbf{X}'\textbf{Z}\widehat{\textbf{W}}\textbf{Z}'\textbf{Y}) \tag{13}$$` --- name: TSLS # <span style="font-size:80%">System two-stage least squares estimator</span> <font size = "5"> A choice of `\(\widehat{\textbf{W}}\)` that leads to a usual and familiar-looking estimator is `$$\widehat{\textbf{W}} = \left(N^{-1}\sum_{i=1}^N \textbf{Z}'_i \textbf{Z}_i \right)^{-1} = (\textbf{Z}'\textbf{Z}/N)^{-1} \tag{14}$$` When we plug equation (14) into equation (13) and cancel `\(N\)` everywhere, we get `$$\widehat{\boldsymbol\beta} = \left[\textbf{X}'\textbf{Z}(\textbf{Z}'\textbf{Z})^{-1}\textbf{Z}'\textbf{X}\right]^{-1}\left[\textbf{X}'\textbf{Z}(\textbf{Z}'\textbf{Z})^{-1}\textbf{Z}'\textbf{Y}\right] \tag{15}$$` This is the <span style="color:blue">system 2SLS (S2SLS) estimator --- name: OWM # <span style="font-size:80%">Optimal weight matrix</span> <font size = "4"> - Given that a GMM estimator exists for any positive definite weighting matrix, it is important to have a way of choosing among all of the possibilities - It turns out that there is a choice of `\(\textbf{W}\)` that produces the GMM estimator with the smallest asymptotic variance, it is achieved when <p style="margin-bottom: -1em"> `$$\textbf{W} = \boldsymbol\Lambda^{-1}$$` `$$\boldsymbol\Lambda = \text{Var}(\textbf{Z}'_i\textbf{u}_i)=E(\textbf{Z}'_i\textbf{u}_i\textbf{u}'_i\textbf{Z}_i)$$` - Procedure <p style="margin-bottom: -1em"> 1. Let `\(\check{\boldsymbol\beta}\)` be an initial consistent estimator of `\(\boldsymbol\beta\)`. In most cases this is the system 2SLS estimator <p style="margin-bottom: -0.5em"> 2. Obtain the `\(T\)` x `\(1\)` residual vectors `\(\check{\textbf{u}}_i=\textbf{y}_i - \textbf{X}_i\check{\boldsymbol\beta}\)` <p style="margin-bottom: -0.5em"> 3. A generally consistent estimator of `\(\boldsymbol\Lambda\)` is `\(\widehat{\boldsymbol\Lambda} = N^{-1}\sum_{i=1}^N\textbf{Z}'_i\check{\textbf{u}}_i\check{\textbf{u}}'_i\textbf{Z}_i\)` <p style="margin-bottom: -0.5em"> 4. Choose <p style="margin-bottom: -1em"> `$$\widehat{\textbf{W}} = \left(N^{-1}\sum_{i=1}^N\textbf{Z}'_i\check{\textbf{u}}_i\check{\textbf{u}}'_i\textbf{Z}_i\right)^{-1}$$` and use this matrix to obtain the asymptotically optimal GMM estimator <p style="margin-bottom: 2em"> - The GMM estimator using the optimal weighting matrix is called the <span style="color:blue">minimum chi-square estimator</span>: `\(\widehat{\boldsymbol\beta}\)` is chosen to make the minimum of the objective function (12) that has an asymptotic chi-square distribution --- name: R # <span style="font-size:80%">Application using R</span> <font size = "5"> We use data from a subsample of the NLSY data on young women aged 14-26 years in 1968. We have a longitudinal dataset of women surveyed during the period 1968-1988 (with gaps). The data is saved in the file nlswork.dta In the follow links you can found data, data description and code used in R: - [Data](http://www.stata-press.com/data/r14/nlswork.dta) - [Data description](https://rdrr.io/rforge/sampleSelection/man/nlswork.html) - [Code in R](https://gusgarciacruz.github.io/EconometriaAvanzadaII/ModelosPanelGMM/L2.R) --- # <span style="font-size:80%">Application using R</span> <font size = "4"> .small-code[ User Library <p style="margin-bottom: -0.8em"> ```r library(haven); library(plm); library(tidyverse); library(summarytools); library(AER); library(gmm); library(modelsummary); library(gt); library(DT) ``` <p style="margin-bottom: 2em"> Reading data and processing information. We have 4711 women employed, not enrrolled in school and who have completed their education <p style="margin-bottom: -0.8em"> ```r nlswork <- read_dta("http://www.stata-press.com/data/r10/nlswork.dta") %>% # leemos la base de datos mutate(age2 = age*age) %>% # construimos la variables age2 select(idcode, year, ln_wage, age, age2, tenure, union, not_smsa, south) |> # seleccionando var filter(union !='NA', south !='NA') ``` <p style="margin-bottom: 2em"> Set panel structure <p style="margin-bottom: -0.8em"> ```r nlswork <- pdata.frame(nlswork, c("idcode","year")) datatable(head(nlswork, 5)) ```
] --- # <span style="font-size:80%">Application using R</span> <font size = "4"> Regressions IV in datapanel .small-code[ ```r # OLS ols_pool <- lm(ln_wage ~ tenure+age+I(age2)+not_smsa, data=nlswork) # IV1 iv1_pool <- ivreg(ln_wage ~ tenure+age+I(age2)+not_smsa | union+south+age+I(age2)+not_smsa, data=nlswork) # IV2 iv2_pool <- tsls(ln_wage ~ tenure+age+I(age2)+not_smsa, ~ union+south+age+I(age2)+not_smsa, data=nlswork) # IV3 iv3_pool <- plm(ln_wage ~ tenure + age + I(age2) + not_smsa | union + south + age + I(age2) + not_smsa, data = nlswork, model = "pooling") # GMM with vcov="iid" gmm_iid <- gmm(ln_wage ~ tenure+age+I(age2)+not_smsa, ~ union+south+age+I(age2)+not_smsa, data=nlswork, vcov="iid") # GMM with vcov="HAC" gmm_hac <- gmm(ln_wage ~ tenure+age+I(age2)+not_smsa, ~ union+south+age+I(age2)+not_smsa, data=nlswork, vcov="HAC") models <- list("OLS" = lm(ln_wage ~ tenure+age+I(age2)+not_smsa, data=nlswork), "IV1" = ivreg(ln_wage ~ tenure+age+I(age2)+not_smsa | union+south+age+I(age2)+not_smsa, data=nlswork), "IV2" = tsls(ln_wage ~ tenure+age+I(age2)+not_smsa, ~ union+south+age+I(age2)+not_smsa, data=nlswork), "IV3" = plm(ln_wage ~ tenure + age + I(age2) + not_smsa | union + south + age + I(age2) + not_smsa, data = nlswork, model = "pooling"), "GMM iid" = gmm(ln_wage ~ tenure+age+I(age2)+not_smsa, ~ union+south+age+I(age2)+not_smsa, data=nlswork, vcov="iid"), "GMM hac" = gmm(ln_wage ~ tenure+age+I(age2)+not_smsa, ~ union+south+age+I(age2)+not_smsa, data=nlswork, vcov="HAC")) ``` ] --- # <span style="font-size:80%">Application using R</span> <p style="margin-bottom: -1.2em"> ```r modelsummary(models, output="gt", coef_map = c('tenure' = 'Tenure', 'age' = 'Age', 'I(age2)' = 'Age2', 'not_smsa' = 'Not SMSA (=1)', '(Intercept)' = 'Constant'), estimate = "{estimate}{stars}", title = "Table 1. Effects of tenure on wages", gof_omit='IC|Log|F|R2', stars = c('*'=.1,'**'=.05,'***'=.01)) |> tab_style(style = cell_text(size = 'small'), locations = cells_body()) |> tab_style(style = cell_text(color='blue'), location = cells_body(row=1:2)) |> tab_style(style = cell_text(color='black', size='x-small'), locations = cells_source_notes()) |> tab_source_note(source_note = "Note: standard errors in parentheses. * p < 0.1, ** p < 0.05, *** p < 0.01") ```
<caption>Table 1. Effects of tenure on wages</caption>
OLS
IV1
IV2
IV3
GMM iid
GMM hac
Tenure
0.037***
0.149***
0.149***
0.149***
0.149***
0.136***
(0.001)
(0.007)
(0.007)
(0.007)
(0.007)
(0.011)
Age
0.047***
0.025***
0.025***
0.025***
0.025***
0.026***
(0.005)
(0.007)
(0.007)
(0.007)
(0.007)
(0.010)
Age2
-0.001***
-0.001***
-0.001***
-0.001***
-0.001***
-0.001***
(0.000)
(0.000)
(0.000)
(0.000)
(0.000)
(0.000)
Not SMSA (=1)
-0.251***
-0.249***
-0.249***
-0.249***
-0.249***
-0.243***
(0.007)
(0.010)
(0.010)
(0.010)
(0.010)
(0.017)
Constant
0.901***
1.209***
1.209***
1.209***
1.209***
1.189***
(0.070)
(0.102)
(0.102)
(0.102)
(0.102)
(0.136)
Num.Obs.
19007
19007
19007
19007
19007
19007
RMSE
0.42
0.60
0.60
Note: standard errors in parentheses. * p < 0.1, ** p < 0.05, *** p < 0.01