{ "cells": [ { "cell_type": "markdown", "id": "continuing-distinction", "metadata": {}, "source": [ "# Introduction to Panel Data\n", "\n", "In this chapter we\\'ll discuss how to implement a model that relaxes\n", "some of the restrictions inherent in the OLS model for cases where you have\n", "panel data. To formalize what we mean by panel data, consider a sample\n", "of $N$ individuals, who are each observed in one of $T$ time periods\n", "[^1]. The model we consider here allows for *partial parameter\n", "heterogeneity*, that is an unobservable individual-specific bit of\n", "information varies from individual to individual.\n", "\n", "Consider the following figure outlining the effect of possible bias\n", "resulting from using a simple OLS model in cases like this. We might\n", "ignore any heterogeneity in the relationship (assuming in a pooled model\n", "that all $\\beta$\\'s are the same across the three individuals) and\n", "estimate a relationship like the one depicted in the figure and labeled\n", "'OLS Estimate\\'. Note that this model restricts $c_i=c$\n", "$\\forall i\\in N$. The true relationship, however, as depicted by the\n", "colored lines, may exhibit parameter heterogeneity (note that the\n", "constant term for each of the dotted lines is different) across groups,\n", "while the slope coefficient is the same across the three groups [^2].\n", "Note that not only do we recover the wrong constant terms using OLS, we\n", "also have an estimated regression line that has the wrong sign compared\n", "to the \"true\" relationship.\n", "\n", "```{figure} /_static/lectures/panel_intro/fe_bias.png\n", ":scale: 35%\n", ":name: \n", "\n", "Bias if we ignore individual heterogeneity\n", "```\n", "\n", "However, there may be cases, where ordinary least squares doesn\\'t fare\n", "as poorly and yields consistent estimates for $\\beta$. The following\n", "figure shows such a case (that as we will see is suitable for the Random\n", "Effects Model).\n", "\n", "```{figure} /_static/lectures/panel_intro/random_effects.png\n", ":scale: 35%\n", ":name: \n", "\n", "Sometimes we can ignore individual heterogeneity\n", "```\n", "\n", "## Framework for Panel Data\n", "\n", "To formalize this, consider a model of the dependent variable $y$ that\n", "is a linear function of $K$ independent variables (and parameters) and\n", "an individual specific unobservable factors $c_i$. Write this as\n", "\n", "```{math}\n", "\\begin{equation}\n", "y_{it}=x_{it}\\beta+c_i+\\epsilon_{it}\n", "\\end{equation}\n", "```\n", "where $\\beta$ is of dimension $K\\times 1$. If $c_i$ is uncorrelated with\n", "each $x_{it}$ then we can proceed using OLS and allow the effect of\n", "$c_i$ to be soaked up into the error term. If on the other hand $c_i$ is\n", "correlated with $x_{it}$ ($cov(x_i,c_i) \\ne 0$), then putting the effect\n", "of $c_i$ in the error term can lead to biased estimated of $\\beta$ by\n", "way of missing variable bias.\n", "\n", "Note that we are assuming that the unobserved individual specific\n", "effects ($c_i$) are constant across time. What is the economic meaning\n", "of $c_i$? If we are estimating the labor market decisions of women in\n", "their twenties and we observed these women in each year, then this time\n", "invariant unobservable information might be capturing cognitive ability,\n", "drive and determination, or family upbringing that may well influence\n", "outcomes for an individual but not vary over time. If our unit of\n", "analysis is a firm in an analysis of productivity, $c_i$ might be\n", "capturing information about the managerial ability or organization that\n", "is roughly constant through time. Ultimately, these unobserved factors\n", "are not of direct interest in these models, we need to worry about them\n", "to avoid biased parameters of the marginal effects\n", "\n", "```{math}\n", "\\begin{equation}\n", "\\beta=\\frac{\\partial E[y_{it}|x_{it}]}{\\partial x_{it}}\n", "\\end{equation}\n", "```\n", "To estimate these marginal effects, we need to invoke some assumptions.\n", "As in the OLS case, we need exogeneity\n", "\n", "```{math}\n", "\\begin{equation}\n", "E(\\epsilon_{t}|\\mathbf{x}_{t},\\mathbf{c})=0\n", "\\end{equation}\n", "```\n", "Which gives us the familiar condition that\n", "\n", "```{math}\n", ":label: eq:ols_orthog_assumption\n", "\\begin{equation}\n", " E(\\mathbf{x}_{t}'\\epsilon_{t})=0\n", "\\end{equation}\n", "```\n", "for $t=1,2$. If we assume that $E(\\mathbf{x}_{t}'c)=0$ then we could\n", "pool the data and estimate an OLS model. If this condition does not\n", "hold, however, an OLS model will lead to biased and inconsistent\n", "parameter estimates.\n", "\n", "### A Two Period Example of First Differencing\n", "\n", "Suppose that for each individual, we have a panel of two periods\n", "($t=1,2$). Perhaps we could apply a differencing approach for each\n", "individual i to rid the model of $c_i$, since\n", "\n", "```{math}\n", "\\begin{aligned}\n", " \\Delta y_{i} = & \\beta \\left (x_{i2}-x_{i1} \\right ) + \\left (c_i-c_i \\right) + \\left (\\epsilon_{i2}-\\epsilon_{i1} \\right) \\\\\n", " = & \\Delta x_{i} \\beta + \\Delta \\epsilon_{i}\n", "\\end{aligned}\n", "```\n", "since the individual-specific effect is time invariant, these constants\n", "drop from the model, and we are still left with our parameters of\n", "interest ($\\beta$). So in a panel with two time periods, we are left\n", "with one standard cross section equation consisting of individual level\n", "data denoted by\n", "\n", "$$\\Delta y = \\Delta x \\beta + \\Delta \\epsilon$$\n", "\n", "where\n", "\n", "$$\n", "\\Delta y = \\begin{bmatrix}\n", " \\Delta y_1 \\\\\n", " \\vdots \\\\\n", " \\Delta y_i \\\\\n", " \\vdots \\\\\n", " \\Delta y_N\n", " \\end{bmatrix}\n", "$$\n", "\n", "and $\\Delta x$ is defined in a similar fashion. Will a simple OLS\n", "estimate of this cross section be unbiased and consistent?\n", "\n", "The orthogonality condition is the first place to start with answering\n", "this question. Recall that in a standard regression model of the\n", "previous chapter, the proof of unbiasedness rests with\n", "{eq}`eq:ols_orthog_assumption`, and invoking the fact that\n", "$E(x'\\epsilon)=0$ allows us to show that $E(b)=\\beta$. For OLS to be\n", "unbiased, we need a similar condition here. Note that this means\n", "\n", "```{math}\n", ":label: eq:first_diff_assumption1\n", "\\begin{equation}\n", " E(\\Delta x' \\Delta \\epsilon)=0\n", "\\end{equation}\n", "```\n", "and the following inverse must exist\n", "\n", "```{math}\n", ":label: eq:first_diff_assumption2\n", "\\begin{equation}\n", " (\\Delta x' \\Delta x)^{-1}\n", "\\end{equation}\n", "```\n", "requiring that $\\Delta x$ must be of full rank.\n", "\n", "What are the implications of these assumptions? First consider\n", "{eq}`eq:first_diff_assumption1`. This condition can be\n", "rewritten as\n", "\n", "```{math}\n", "\\begin{aligned}\n", " & E \\left [(x_{2}-x_{1})'(\\epsilon_{2}-\\epsilon_{1}) \\right]=0 \\\\\n", " & E \\left [(x_{2}'\\epsilon_{2}+x_{1}'\\epsilon_{1}-x_{1}'\\epsilon_{2}-x_{2}'\\epsilon_{1}) \\right]=0\n", "\\end{aligned}\n", "```\n", "The first two terms are zero by definition given\n", "assumption {eq}`eq:ols_orthog_assumption`. Note however, that in\n", "this framework, we also need to assume\n", "\n", "```{math}\n", "\\begin{aligned}\n", " E(x_{1}'\\epsilon_{2})&=0 \\\\\n", " E(x_{2}'\\epsilon_{1})&=0\n", "\\end{aligned}\n", "```\n", "these highlight the even more restrictive orthogonality conditions we\n", "need to assume to implement this type of approach.\n", "\n", "It is also useful to think carefully about\n", "{eq}`eq:first_diff_assumption2`. Since the matrix\n", "$\\Delta x$ is comprised of elements differenced across two periods, x\n", "may not contain any variable that is constant across time for every\n", "person in the sample. For example, if the Kth element of x were to\n", "contain a dummy variable equal 1 if a person\\'s sex is female and 0 if\n", "male, then\n", "\n", "$$\n", "\\Delta x_K= \\begin{bmatrix} \n", " \\color{blue}{1-1} \\\\\n", " \\color{blue}{\\vdots} \\\\\n", " \\color{blue}{1-1} \\\\\n", " \\vdots \\\\\n", " \\color{red}{0-0} \\\\\n", " \\color{red}{\\vdots} \\\\\n", " \\color{red}{0-0} \\\\\n", " \\vdots \\\\\n", " \\color{green}{1-1} \\\\\n", " \\color{green}{\\vdots} \\\\\n", " \\color{green}{1-1} \\\\\n", " \\end{bmatrix}\n", "$$\n", "\n", "so the matrix $\\Delta x$ would not be of full rank since every element\n", "in column K is equal to zero. For some of the panel data models we will\n", "consider (i.e. the Fixed Effects Model), your independent variables\n", "*must* vary across periods in your panel. This is very important to\n", "remember.\n", "\n", "## Random or Fixed Effects\n", "\n", "Following from our framework above, the unobserved effects model can be\n", "written\n", "\n", "$$\n", "y_{it}=x_{it}\\beta+c_i+\\epsilon_{it}\n", "$$\n", "\n", "where $x_{it}$ is $1 \\times K$. The literature has implemented this type\n", "of model in a number of ways, but the most prevalent are termed (1)\n", "random effects and (2) fixed effects. These terms refer to assumptions\n", "about the individual-specific constant terms $c_i$.\n", "\n", "The labels fixed and random effects are misleading. What matters here is\n", "the nature of the unobserved, time invariant, and individual-specific\n", "quantities. If there is a dependence between these unobserved factors\n", "and the observed independent variables we employ the fixed effects\n", "approach. If on the other hand, these effects are independent of the\n", "observed independent variables, then we use the random effects\n", "estimator. We will explore the difference in the models, compare these\n", "approaches to Pooled OLS, and develop some test statistics for model\n", "selection.\n", "\n", "## The Pooled OLS Model\n", "\n", "The pooled model simply applies an OLS estimate to the pooled data set\n", "(where each individual i\\'s data is ordered from $t=1,\\ldots,T$, and\n", "then vertically stacked.). For a data set of N individuals across T\n", "periods, the vector $y$ and the matrix $x$ will look like\n", "\n", "$$\n", "y=\\begin{bmatrix}\n", " \\color{blue}{y_{11}} \\\\\n", " \\color{blue}{\\vdots} \\\\\n", " \\color{blue}{y_{1T}} \\\\\n", " \\vdots \\\\\n", " \\color{red}{y_{i1}} \\\\\n", " \\color{red}{\\vdots} \\\\\n", " \\color{red}{y_{iT}} \\\\\n", " \\vdots \\\\\n", " \\color{green}{y_{N1}} \\\\\n", " \\color{green}{\\vdots} \\\\\n", " \\color{green}{y_{NT}} \\\\\n", " \\end{bmatrix}\n", " x=\\begin{bmatrix}\n", " \\color{blue}{x_{111} \\ldots x_{11k} \\ldots x_{11K}}\\\\\n", " \\color{blue}{\\ddots} \\\\\n", " \\color{blue}{x_{1T} \\ldots x_{1T} \\ldots x_{1T}}\\\\\n", " \\vdots \\\\\n", " \\color{red}{x_{i1} \\ldots x_{i1} \\ldots x_{i1}}\\\\\n", " \\color{red}{\\ddots} \\\\\n", " \\color{red}{x_{iT} \\ldots x_{iT} \\ldots x_{iT}}\\\\\n", " \\vdots \\\\\n", " \\color{green}{x_{N1} \\ldots x_{N1} \\ldots x_{N1}}\\\\\n", " \\color{green}{\\ddots} \\\\\n", " \\color{green}{x_{NT} \\ldots x_{NT} \\ldots x_{NT}} \\\\\n", " \\end{bmatrix}\n", "$$\n", "\n", "For pooled OLS to be the appropriate estimator, we need to assume\n", "\n", "**Assumption 1: Strict Endogeneity**\n", "\n", "$$E[\\epsilon_{it}|x_{i1},\\ldots,x_{iT}]=0$$\n", "\n", "**Assumption 2: Uncorrelated individual-specific effects**\n", "\n", "$$E[c_i|x_{i1},\\ldots,x_{iT}]=0$$\n", "\n", "Defining $v_{it}=c_i+\\epsilon_{it}$ now completely uncorrelated with the\n", "covariates, we have an error structure with orthogonality just as in the\n", "previous chapter and our analysis of the OLS model. So we can recover\n", "the parameter using\n", "\n", "$$\\mathbf{b_{ols}}=\\mathbf{(x'x)}^{-1}\\mathbf{x'y}$$\n", "\n", "The usual estimate for the variance covariance matrix, and associated\n", "standard errors is\n", "\n", "$$Var[\\mathbf{b_{ols}}]=\\mathbf{\\sigma^2E_x[(x'x)^{-1}]}$$\n", "\n", "Taking note of the error structure inherent in an OLS model (where\n", "$\\epsilon_{i}\\sim N(0,\\sigma I)$) compared to this case where the error\n", "contain the usual $\\epsilon_{it}\\sim N(0,\\sigma)$ *plus* $c_i$ which is\n", "shared by each cross section unit (e.g. each individual or firm). This\n", "may well introduce a systematic relationship between the composite error\n", "($v_{it}$) among cross section units that the OLS variance-covariance\n", "estimate ignores. To fix, this can apply the robust standard errors\n", "using the technique we discussed in the previous chapter.\n", "\n", "Following the recovery of $\\mathbf{b_{ols}}$, calculate the estimated\n", "residuals\n", "\n", "$$\\mathbf{\\hat{v}=y-x b_{ols}}$$\n", "\n", "Using the notation adopted in the OLS Chapter for correcting for\n", "heteroskedasticity, the expected variance-covariance matrix for the\n", "error is\n", "\n", "$$\\label{eq:het_correction_pooled_OLS}\n", " E[var(\\mathbf{vv'})]=\\hat{\\mathbf{V}}=diagonal\\left(\\hat{\\mathbf{v}}\\hat{\\mathbf{v}}' \\right )_{N \\times N}$$\n", "\n", "let\\'s us write the robust pooled variance covariance matrix of the\n", "parameters as\n", "\n", "$$Var^{robust}=\\mathbf{(x'x)^{-1}(x'\\hat{V}x)(x'x)^{-1}}$$\n", "\n", "Notice that this equation is exactly equivalent to the definition of\n", "robust standard errors in OLS and highlites the strong assumptions we\n", "are making when we estimate panel data with a pooled OLS model.\n", "\n", "## Implementation in R and Stata\n", "\n", "The companion chapter shows how to implement many of these ideas in R and Stata.\n", "\n", "[^1]: In this chapter we will be assuming balanced panels- that is each\n", " individual is assumed for each of the $T$ time periods. Unbalanced\n", " panels, where each individual is observed for $T_i$ periods, where\n", " $T_i \\le T$, are also possible and are implemented in most cases\n", " seamlessly in Stata. While the mechanics of unbalanced panels are\n", " trivial extensions of what we do here, the potential selection bias\n", " associated with individuals joining and dropping in and out of a\n", " panel data set should be thought about very seriously.\n", "\n", "[^2]: It is also possible that rather than partial parameter\n", " heterogeneity *all* parameters differ across individuals- both\n", " constant terms and slope coefficients. We do not consider this\n", " case in this chapter, but will briefly discuss it in the advanced\n", " topics chapter. This model is the one referred to by Greene\n", " {cite}`greene2003econometric` on page 183 as Model 4, Random\n", " Parameters." ] } ], "metadata": { "jupytext": { "text_representation": { "extension": ".md", "format_name": "myst", "format_version": 0.13, "jupytext_version": "1.10.3" } }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" }, "source_map": [ 12 ] }, "nbformat": 4, "nbformat_minor": 5 }