Panel Data Analysis

Panel Data Analysis – Employment in the UK

Research Question: To what extent do wages, capital, and output explain variation in firm level employment in the UK between 1978-1984?

Here, we uploaded the “plm” pack needed for panel data analysis and drew the “EmplUK” data set from it.

The data set has data from 140 firms for sectors, employment, wages, capital and output between the years 1976-1984.

According to the manual to the data set, the variables are measured in the units below:

  • Employment –> Thousand of employees

  • Wage –> Thousands of GBP

  • Capital –> Millions of GBP

  • Output –> Millions of GBP

library(plm)
data("EmplUK", package = "plm")
head(EmplUK)
  firm year sector   emp    wage capital   output
1    1 1977      7 5.041 13.1516  0.5894  95.7072
2    1 1978      7 5.600 12.3018  0.6318  97.3569
3    1 1979      7 5.015 12.8395  0.6771  99.6083
4    1 1980      7 4.715 13.8039  0.6171 100.5501
5    1 1981      7 4.093 14.2897  0.5076  99.5581
6    1 1982      7 3.166 14.8681  0.4229  98.6151
summary(EmplUK)
      firm            year          sector           emp         
 Min.   :  1.0   Min.   :1976   Min.   :1.000   Min.   :  0.104  
 1st Qu.: 37.0   1st Qu.:1978   1st Qu.:3.000   1st Qu.:  1.181  
 Median : 74.0   Median :1980   Median :5.000   Median :  2.287  
 Mean   : 73.2   Mean   :1980   Mean   :5.123   Mean   :  7.892  
 3rd Qu.:110.0   3rd Qu.:1981   3rd Qu.:8.000   3rd Qu.:  7.020  
 Max.   :140.0   Max.   :1984   Max.   :9.000   Max.   :108.562  
      wage           capital            output     
 Min.   : 8.017   Min.   : 0.0119   Min.   : 86.9  
 1st Qu.:20.636   1st Qu.: 0.2210   1st Qu.: 97.1  
 Median :24.006   Median : 0.5180   Median :100.6  
 Mean   :23.919   Mean   : 2.5074   Mean   :103.8  
 3rd Qu.:27.494   3rd Qu.: 1.5010   3rd Qu.:110.6  
 Max.   :45.232   Max.   :47.1079   Max.   :128.4  

Here, we redefined the data set as panel data and checked to see if it is balanced. It is not balanced, meaning not all firms have all data for all years.

We checked if there were any missing data, there wasn’t.

empl_data <- pdata.frame(EmplUK, index = c("firm", "year"))
is.pbalanced(empl_data)
[1] FALSE
sapply(empl_data, function(x) sum(is.na(x)))
   firm    year  sector     emp    wage capital  output 
      0       0       0       0       0       0       0 

Pooled OLS Model

pooled_model <- plm(emp ~ wage + capital + output, data = empl_data, model = "pooling")
summary(pooled_model)
Pooling Model

Call:
plm(formula = emp ~ wage + capital + output, data = empl_data, 
    model = "pooling")

Unbalanced Panel: n = 140, T = 7-9, N = 1031

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-79.77766  -2.54599  -0.99936   1.19158  47.18957 

Coefficients:
             Estimate Std. Error t-value  Pr(>|t|)    
(Intercept)  8.252019   3.108688  2.6545  0.008065 ** 
wage        -0.324252   0.048761 -6.6498 4.761e-11 ***
capital      2.105611   0.044085 47.7623 < 2.2e-16 ***
output       0.020382   0.027720  0.7353  0.462337    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    261540
Residual Sum of Squares: 80229
R-Squared:      0.69324
Adj. R-Squared: 0.69235
F-statistic: 773.642 on 3 and 1027 DF, p-value: < 2.22e-16

Here, we ran the pooled OLS model. Like we discussed in the lecture, this model doesn’t account for firm and time specific differences and ignores the panel nature of the data.

  • The intercept doesn’t matter in this case, because it doesn’t make sense for a firm to have 0 wages, 0 capital, 0 output etc.
Coefficient p-value
Wage -0.32 <0.001
Capital +2.11 <0.001
Output +0.02 0.46
  • Wage has a significant negative effect on employment. A 1 unit increase in wage, results in a 0.32 unit decrease in employment on average (across all firms and years).

  • Capital has a strong positive effect on employment. For every unit of increase in capital, emplyment also increases by 2.11 units.

  • Output is not significant.

  • R² = 0.69 –> the model explains about 69% of the variation in employment.

However, because the pooled OLS model ignores between (firms) and within (a firm over time) variation and also because it cannot control for time-invariant factors (e.g. sector, firm culture etc.) which might affect employment, the results might be “naive”.

FE1: Least Squares Dummy Variable - LSDV

To control for unobserved, time-invariant characteristics of each firm, we used LSDV.

Because we didn’t define which firm should be the reference / base - R automatically used Firm 1 as the reference. This means for each firm, the co-efficient we get shows how that firm’s average employment differs from Firm 1, after accounting for wage, capital and output.

  • Dummy variables (Firm 1 in this case) “soak up” all between-firm variation, so that the model shows only within-firm changes. This is how unobserved, time invariant factors are controlled for.
lsdv_model <- lm(emp ~ wage + capital + output + factor(firm), data = empl_data)
summary(lsdv_model)

Call:
lm(formula = emp ~ wage + capital + output + factor(firm), data = empl_data)

Residuals:
     Min       1Q   Median       3Q      Max 
-16.6008  -0.3803  -0.0029   0.4071  26.4877 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)      -0.474029   1.211990  -0.391 0.695805    
wage             -0.101641   0.032164  -3.160 0.001630 ** 
capital           0.751130   0.062323  12.052  < 2e-16 ***
output            0.058807   0.007466   7.877 9.77e-15 ***
factor(firm)2    54.750483   1.526157  35.875  < 2e-16 ***
factor(firm)3    11.082573   1.228131   9.024  < 2e-16 ***
factor(firm)4    15.390452   1.235384  12.458  < 2e-16 ***
factor(firm)5    63.686790   1.859495  34.250  < 2e-16 ***
factor(firm)6    -2.704403   1.166000  -2.319 0.020600 *  
factor(firm)7    -1.698156   1.248106  -1.361 0.173990    
factor(firm)8     3.707528   1.245287   2.977 0.002987 ** 
factor(firm)9    -0.915276   1.177271  -0.777 0.437097    
factor(firm)10   -0.282089   1.165844  -0.242 0.808866    
factor(firm)11   -2.436996   1.167156  -2.088 0.037084 *  
factor(firm)12   -1.361360   1.268047  -1.074 0.283299    
factor(firm)13   -1.967584   1.194281  -1.648 0.099808 .  
factor(firm)14   -1.326546   1.176125  -1.128 0.259669    
factor(firm)15    1.938182   1.164269   1.665 0.096321 .  
factor(firm)16   -0.968371   1.207356  -0.802 0.422733    
factor(firm)17   -2.532261   1.197229  -2.115 0.034699 *  
factor(firm)18    2.708505   1.199352   2.258 0.024169 *  
factor(firm)19   13.604824   1.286502  10.575  < 2e-16 ***
factor(firm)20   -2.081962   1.199020  -1.736 0.082842 .  
factor(firm)21   -0.849516   1.211587  -0.701 0.483387    
factor(firm)22   -2.020870   1.172853  -1.723 0.085230 .  
factor(firm)23    4.124849   1.227416   3.361 0.000811 ***
factor(firm)24   -1.869754   1.184221  -1.579 0.114717    
factor(firm)25   -2.023701   1.230675  -1.644 0.100451    
factor(firm)26   -0.340142   1.202950  -0.283 0.777429    
factor(firm)27    2.312338   1.195407   1.934 0.053387 .  
factor(firm)28   -3.194724   1.126196  -2.837 0.004661 ** 
factor(firm)29   -1.381499   1.239004  -1.115 0.265149    
factor(firm)30   -1.991662   1.208950  -1.647 0.099823 .  
factor(firm)31   -1.731603   1.180089  -1.467 0.142635    
factor(firm)32   -1.644150   1.150627  -1.429 0.153380    
factor(firm)33    7.109303   1.184573   6.002 2.84e-09 ***
factor(firm)34   -2.486029   1.129445  -2.201 0.027985 *  
factor(firm)35    4.233701   1.231633   3.437 0.000614 ***
factor(firm)36   -2.608330   1.169582  -2.230 0.025987 *  
factor(firm)37    8.741985   1.275185   6.855 1.33e-11 ***
factor(firm)38    2.830194   1.194203   2.370 0.018004 *  
factor(firm)39   -1.681424   1.219804  -1.378 0.168415    
factor(firm)40    8.434272   1.197722   7.042 3.80e-12 ***
factor(firm)41    9.672568   1.211576   7.983 4.39e-15 ***
factor(firm)42   -2.016714   1.168366  -1.726 0.084678 .  
factor(firm)43    7.933882   1.163748   6.818 1.71e-11 ***
factor(firm)44   -2.769163   1.160201  -2.387 0.017204 *  
factor(firm)45   18.727898   1.402625  13.352  < 2e-16 ***
factor(firm)46   -2.027006   1.161894  -1.745 0.081406 .  
factor(firm)47   -1.738320   1.179857  -1.473 0.141016    
factor(firm)48   -1.913934   1.197630  -1.598 0.110376    
factor(firm)49   -0.670385   1.169230  -0.573 0.566549    
factor(firm)50   43.009260   1.814679  23.701  < 2e-16 ***
factor(firm)51   -3.351164   1.184099  -2.830 0.004758 ** 
factor(firm)52    7.567722   1.174702   6.442 1.93e-10 ***
factor(firm)53    2.024803   1.168771   1.732 0.083546 .  
factor(firm)54   -0.442014   1.187546  -0.372 0.709827    
factor(firm)55    3.867102   1.318141   2.934 0.003435 ** 
factor(firm)56   -1.750374   1.170801  -1.495 0.135264    
factor(firm)57   -2.894952   1.128477  -2.565 0.010470 *  
factor(firm)58   11.427435   1.267090   9.019  < 2e-16 ***
factor(firm)59    2.530777   1.136694   2.226 0.026235 *  
factor(firm)60   -2.253055   1.163561  -1.936 0.053143 .  
factor(firm)61   -1.297963   1.160631  -1.118 0.263731    
factor(firm)62   -1.905305   1.132533  -1.682 0.092855 .  
factor(firm)63   -1.709194   1.301907  -1.313 0.189577    
factor(firm)64    4.991160   1.230510   4.056 5.43e-05 ***
factor(firm)65   14.903939   1.274618  11.693  < 2e-16 ***
factor(firm)66    1.334199   1.287157   1.037 0.300229    
factor(firm)67    6.752243   1.144202   5.901 5.13e-09 ***
factor(firm)68   -1.189308   1.284062  -0.926 0.354590    
factor(firm)69   -1.575432   1.231239  -1.280 0.201038    
factor(firm)70   -1.449156   1.164032  -1.245 0.213480    
factor(firm)71   -1.940835   1.176074  -1.650 0.099242 .  
factor(firm)72    7.201830   1.274004   5.653 2.13e-08 ***
factor(firm)73   -1.147046   1.297063  -0.884 0.376752    
factor(firm)74   -0.745751   1.161684  -0.642 0.521067    
factor(firm)75   -0.891390   1.192518  -0.747 0.454969    
factor(firm)76    1.038104   1.199152   0.866 0.386889    
factor(firm)77    1.108821   1.143584   0.970 0.332509    
factor(firm)78    3.405260   1.189167   2.864 0.004288 ** 
factor(firm)79   -2.538212   1.157951  -2.192 0.028640 *  
factor(firm)80   -0.971500   1.165345  -0.834 0.404697    
factor(firm)81   -2.537986   1.179934  -2.151 0.031749 *  
factor(firm)82    2.645295   1.342134   1.971 0.049038 *  
factor(firm)83    0.990152   1.201383   0.824 0.410060    
factor(firm)84    8.794107   1.154075   7.620 6.50e-14 ***
factor(firm)85   19.078465   1.231878  15.487  < 2e-16 ***
factor(firm)86   70.683846   2.541760  27.809  < 2e-16 ***
factor(firm)87   32.316180   1.322035  24.444  < 2e-16 ***
factor(firm)88    4.003990   1.274712   3.141 0.001739 ** 
factor(firm)89   -2.199715   1.238704  -1.776 0.076105 .  
factor(firm)90    3.120681   1.280782   2.437 0.015024 *  
factor(firm)91   -2.418608   1.251552  -1.932 0.053617 .  
factor(firm)92   -2.746098   1.166566  -2.354 0.018790 *  
factor(firm)93   55.292088   2.158926  25.611  < 2e-16 ***
factor(firm)94   -0.918666   1.220121  -0.753 0.451691    
factor(firm)95   -2.887329   1.205684  -2.395 0.016837 *  
factor(firm)96   37.881177   1.312054  28.872  < 2e-16 ***
factor(firm)97   15.265058   1.208925  12.627  < 2e-16 ***
factor(firm)98   -1.096685   1.295809  -0.846 0.397596    
factor(firm)99   -2.101554   1.197300  -1.755 0.079562 .  
factor(firm)100   0.318419   1.180315   0.270 0.787397    
factor(firm)101   0.038770   1.151913   0.034 0.973158    
factor(firm)102  -2.355593   1.214313  -1.940 0.052713 .  
factor(firm)103  -2.867548   1.147349  -2.499 0.012624 *  
factor(firm)104  -2.498438   1.106443  -2.258 0.024183 *  
factor(firm)105  -2.500967   1.176047  -2.127 0.033730 *  
factor(firm)106  -2.734288   1.093477  -2.501 0.012580 *  
factor(firm)107  -3.238638   1.090696  -2.969 0.003065 ** 
factor(firm)108  -2.832202   1.142257  -2.479 0.013342 *  
factor(firm)109   0.056229   1.094319   0.051 0.959033    
factor(firm)110   0.168543   1.155627   0.146 0.884076    
factor(firm)111  -1.499545   1.145433  -1.309 0.190822    
factor(firm)112  -0.840814   1.128764  -0.745 0.456531    
factor(firm)113  -1.587091   1.135215  -1.398 0.162446    
factor(firm)114  -2.776622   1.134775  -2.447 0.014604 *  
factor(firm)115  -2.352444   1.102325  -2.134 0.033110 *  
factor(firm)116  -2.130556   1.113250  -1.914 0.055965 .  
factor(firm)117   3.334704   1.117732   2.983 0.002928 ** 
factor(firm)118  -0.514190   1.093904  -0.470 0.638434    
factor(firm)119  -1.065834   1.186711  -0.898 0.369353    
factor(firm)120  -1.910163   1.140097  -1.675 0.094200 .  
factor(firm)121  -1.680262   1.165100  -1.442 0.149609    
factor(firm)122  -0.443662   1.183608  -0.375 0.707870    
factor(firm)123  -2.990323   1.104956  -2.706 0.006935 ** 
factor(firm)124  -2.282315   1.227257  -1.860 0.063260 .  
factor(firm)125  -3.370134   1.114961  -3.023 0.002578 ** 
factor(firm)126  -2.991079   1.160770  -2.577 0.010132 *  
factor(firm)127  -3.082523   1.061418  -2.904 0.003774 ** 
factor(firm)128  -2.533477   1.060807  -2.388 0.017137 *  
factor(firm)129  -3.802538   1.072093  -3.547 0.000410 ***
factor(firm)130 -14.939753   2.640844  -5.657 2.08e-08 ***
factor(firm)131  -0.535088   1.109236  -0.482 0.629645    
factor(firm)132  -3.262535   1.091540  -2.989 0.002877 ** 
factor(firm)133  -1.054238   1.121982  -0.940 0.347667    
factor(firm)134   8.379007   1.066958   7.853 1.17e-14 ***
factor(firm)135  -2.329416   1.074220  -2.168 0.030388 *  
factor(firm)136  -3.073902   1.099640  -2.795 0.005296 ** 
factor(firm)137  -0.364197   1.266833  -0.287 0.773807    
factor(firm)138  -1.193310   1.135515  -1.051 0.293591    
factor(firm)139  -2.393157   1.084019  -2.208 0.027522 *  
factor(firm)140  -1.863372   1.177491  -1.582 0.113893    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.105 on 888 degrees of freedom
Multiple R-squared:  0.985, Adjusted R-squared:  0.9826 
F-statistic: 409.6 on 142 and 888 DF,  p-value: < 2.2e-16
Coefficient p-value
Wage -0.10 0.0016
Capital +0.75 <0.001
Output +0.059 <0.001

Now these coefficients need to be interpreted within the same over time. So,

  • Wage: 1 unit increase in wage is associated with a 0.10 unit decrease in employment, within the same firm over time.

  • Capital: 1 unit increase in capital is associated with a 0.75-unit increase in employment, within the same firm over time.

  • R² = 0.985 —> Almost all of the variation in employment is explained by the model.

The model removes time-invariant variables and doesn’t account for them (overestimates explanatory power) and is inefficient for high number of units (firms).

FE2: Demeaned Fixed Effects

fixed_model <- plm(emp ~ wage + capital + output, data = empl_data, model = "within")
summary(fixed_model)
Oneway (individual) effect Within Model

Call:
plm(formula = emp ~ wage + capital + output, data = empl_data, 
    model = "within")

Unbalanced Panel: n = 140, T = 7-9, N = 1031

Residuals:
       Min.     1st Qu.      Median     3rd Qu.        Max. 
-16.6007954  -0.3803183  -0.0028994   0.4071307  26.4876927 

Coefficients:
          Estimate Std. Error t-value  Pr(>|t|)    
wage    -0.1016412  0.0321637 -3.1601   0.00163 ** 
capital  0.7511302  0.0623233 12.0522 < 2.2e-16 ***
output   0.0588070  0.0074657  7.8770 9.772e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    5030.6
Residual Sum of Squares: 3933
R-Squared:      0.21819
Adj. R-Squared: 0.093166
F-statistic: 82.6066 on 3 and 888 DF, p-value: < 2.22e-16

RE: Random Effects Model

random_model <- plm(emp ~ wage + capital + output, data = empl_data, model = "random")
summary(random_model)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = emp ~ wage + capital + output, data = empl_data, 
    model = "random")

Unbalanced Panel: n = 140, T = 7-9, N = 1031

Effects:
                 var std.dev share
idiosyncratic  4.429   2.105 0.057
individual    73.212   8.556 0.943
theta:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.9074  0.9074  0.9074  0.9098  0.9134  0.9183 

Residuals:
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-14.0927  -0.6671  -0.2820  -0.0106   0.2028  29.0515 

Coefficients:
              Estimate Std. Error z-value  Pr(>|z|)    
(Intercept)  2.7412853  1.4432778  1.8993 0.0575189 .  
wage        -0.1207583  0.0330594 -3.6528 0.0002594 ***
capital      1.0783753  0.0582626 18.5089 < 2.2e-16 ***
output       0.0537293  0.0078498  6.8447 7.666e-12 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    7228.7
Residual Sum of Squares: 5061.7
R-Squared:      0.2998
Adj. R-Squared: 0.29775
Chisq: 435.933 on 3 DF, p-value: < 2.22e-16

Hausman Test

phtest(fixed_model, random_model)

    Hausman Test

data:  emp ~ wage + capital + output
chisq = 217.52, df = 3, p-value < 2.2e-16
alternative hypothesis: one model is inconsistent

Summary Table

library(stargazer)

Please cite as: 
 Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2.3. https://CRAN.R-project.org/package=stargazer 
library(lmtest)
Loading required package: zoo

Attaching package: 'zoo'
The following objects are masked from 'package:base':

    as.Date, as.Date.numeric
stargazer(
  pooled_model, fixed_model, lsdv_model, random_model,
  type = "text",            
  column.labels = c("Pooled OLS", "FE (Within)", "FE (LSDV)", "RE"),
  digits = 4,
  omit = "factor\\(firm\\)")

===============================================================================================================
                                                        Dependent variable:                                    
                    -------------------------------------------------------------------------------------------
                                                                emp                                            
                                           panel                                    OLS                panel   
                                          linear                                                      linear   
                            Pooled OLS               FE (Within)                 FE (LSDV)              RE     
                               (1)                       (2)                        (3)                 (4)    
---------------------------------------------------------------------------------------------------------------
wage                        -0.3243***                -0.1016***                -0.1016***          -0.1208*** 
                             (0.0488)                  (0.0322)                  (0.0322)            (0.0331)  
                                                                                                               
capital                     2.1056***                 0.7511***                  0.7511***           1.0784*** 
                             (0.0441)                  (0.0623)                  (0.0623)            (0.0583)  
                                                                                                               
output                        0.0204                  0.0588***                  0.0588***           0.0537*** 
                             (0.0277)                  (0.0075)                  (0.0075)            (0.0078)  
                                                                                                               
Constant                    8.2520***                                             -0.4740             2.7413*  
                             (3.1087)                                            (1.2120)            (1.4433)  
                                                                                                               
---------------------------------------------------------------------------------------------------------------
Observations                  1,031                     1,031                      1,031               1,031   
R2                            0.6932                    0.2182                    0.9850              0.2998   
Adjusted R2                   0.6923                    0.0932                    0.9826              0.2978   
Residual Std. Error                                                          2.1045 (df = 888)                 
F Statistic         773.6418*** (df = 3; 1027) 82.6066*** (df = 3; 888) 409.5972*** (df = 142; 888) 435.9325***
===============================================================================================================
Note:                                                                               *p<0.1; **p<0.05; ***p<0.01
  • The pooled OLS overstates effects because it ignores firm level differences.

  • The R squared is as high as it is in FE (LSDV) because the model includes dummies and absorbs firm-level variance.

GRAPHS

library(broom)
library(ggplot2)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:plm':

    between, lag, lead
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
tidy_pooled <- tidy(pooled_model) %>% mutate(model = "Pooled OLS")
tidy_fixed  <- tidy(fixed_model) %>% mutate(model = "Fixed Effects")
tidy_random <- tidy(random_model) %>% mutate(model = "Random Effects")

all_models <- bind_rows(tidy_pooled, tidy_fixed, tidy_random)

Residual Plots

empl_data$resid_pooled <- residuals(pooled_model)
empl_data$resid_fixed  <- residuals(fixed_model)
empl_data$resid_random <- residuals(random_model)
library(ggplot2)
ggplot(empl_data, aes(x = fitted(pooled_model), y = resid_pooled)) +
  geom_point(alpha = 0.5) +
  geom_hline(yintercept = 0, color = "red") +
  labs(title = "Residual Plot: Pooled OLS",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()

ggplot(empl_data, aes(x = fitted(fixed_model), y = resid_fixed)) +
  geom_point(alpha = 0.5) +
  geom_hline(yintercept = 0, color = "red") +
  labs(title = "Residual Plot: Fixed Effects",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()

ggplot(empl_data, aes(x = fitted(random_model), y = resid_random)) +
  geom_point(alpha = 0.5) +
  geom_hline(yintercept = 0, color = "red") +
  labs(title = "Residual Plot: Random Effects",
       x = "Fitted Values", y = "Residuals") +
  theme_minimal()

Actual vs Predicted Employment

empl_data$pred_pooled <- fitted(pooled_model)
empl_data$pred_fixed <- fitted(fixed_model)
empl_data$pred_random <- fitted(random_model)

ggplot(empl_data, aes(x = emp, y = pred_pooled)) +
  geom_point(alpha = 0.5) +
  geom_abline(slope = 1, intercept = 0, color = "red") +
  labs(title = "Actual vs Predicted Employment (Pooled OLS)",
       x = "Actual Employment",
       y = "Predicted Employment") +
  theme_minimal()

ggplot(empl_data, aes(x = emp, y = pred_fixed)) +
  geom_point(alpha = 0.5) +
  geom_abline(slope = 1, intercept = 0, color = "red") +
  labs(title = "Actual vs Predicted Employment (Fixed Effects)",
       x = "Actual Employment",
       y = "Predicted Employment") +
  theme_minimal()

ggplot(empl_data, aes(x = emp, y = pred_random)) +
  geom_point(alpha = 0.5) +
  geom_abline(slope = 1, intercept = 0, color = "red") +
  labs(title = "Actual vs Predicted Employment (Random Effects)",
       x = "Actual Employment",
       y = "Predicted Employment") +
  theme_minimal()

Coefficient Comparison Plot

ggplot(all_models %>% filter(term != "(Intercept)"),
       aes(x = term, y = estimate, color = model)) +
  geom_point(position = position_dodge(width = 0.5)) +
  geom_errorbar(aes(ymin = estimate - std.error, ymax = estimate + std.error),
                width = 0.2,
                position = position_dodge(width = 0.5)) +
  labs(title = "Coefficient Comparison Across Models",
       x = "Variable", y = "Estimate") +
  theme_minimal()