Difference between revisions of "Panel in R"
Line 12: | Line 12: | ||
Here we are using the [[R#Data_Sets|Crime Statistics]] dataset for illustration. It is used in Example 13.9 in Wooldridge's Introductory Econometrics. | Here we are using the [[R#Data_Sets|Crime Statistics]] dataset for illustration. It is used in Example 13.9 in Wooldridge's Introductory Econometrics. | ||
+ | |||
+ | == Set-up of Panel == | ||
+ | |||
+ | Here is our initial data load-up | ||
+ | |||
+ | library(plm) | ||
+ | setwd("X:/ECLR/R/PanelData") # This sets the working directory | ||
+ | # Opens mroz.csv from working directory | ||
+ | # converts variables with "." to num with NA | ||
+ | mydata <- read.csv("crime4.csv",na.strings = ".") | ||
+ | |||
+ | |||
+ | So far we have merely uploaded the csv file. It is worth having a look at the data at this stage | ||
+ | |||
+ | |||
+ | pdata <- plm.data(mydata, index = c("county","year")) # defines the panel dimensions |
Revision as of 15:43, 9 July 2015
In this section we shall discuss how to deal with panel data and how to use econometric techniques that exploit the additional analysis that can be performed due to the Panel character of data.
A lot of this material repeats material that is discussed in this YouTube clip [1].
The plm package
To deal efficiently with panel data we will need the plm
package and you need to downlaod it (install.packages("plm")
) and load it into the workspace (library(plm)
) in the usual manner.
Details for this package can be found here.
Example Data
Here we are using the Crime Statistics dataset for illustration. It is used in Example 13.9 in Wooldridge's Introductory Econometrics.
Set-up of Panel
Here is our initial data load-up
library(plm) setwd("X:/ECLR/R/PanelData") # This sets the working directory # Opens mroz.csv from working directory # converts variables with "." to num with NA mydata <- read.csv("crime4.csv",na.strings = ".")
So far we have merely uploaded the csv file. It is worth having a look at the data at this stage
pdata <- plm.data(mydata, index = c("county","year")) # defines the panel dimensions