0

I am trying to use the NdDd package - https://rdrr.io/rforge/nndd/f/inst/doc/nndd.pdf - and was wondering if anyone would be so kind as to help me with a question I have regarding an error message. Advice hugely appreciated!

I have panel data in the format below. This is all using publicly available data. There are 5 rows for every school - one for each year (the years run from -2 to 2. -2 being 2 years prior to treatment, and +2 being 2 years after). FSM, EAL, SEN, Region I'm only using for matching, so they are same for all 5 rows (trying to match on values for the year prior to intervention). A8 and outcome vary by year.

I'm trying to do nearest neighbour matching followed by linear model with difference in differences, using the code below but getting the following error message:

Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

Any ideas?

Code:

dataset <- read.csv("CLP_data.csv")
View(dataset)

install.packages("NnDd", repos=http://R-Forge.R-project.org)
library(NnDd)
dataset
help(NnDd)

class(dataset$URN)
dataset$URN <- factor(dataset$URN)
class(dataset$Treated)
dataset$Treated <- factor(dataset$Treated)
class(dataset$Time)
dataset$Time <- factor(dataset$Time, order = TRUE, levels =c('-2','-1','0','1','2'))
dataset$Time
class(dataset$Region)
class(dataset$Outcome)

install.packages("Formula")
library(Formula)
formula <- Formula(Treated | Outcome ~ A8 | Region + FSM + EAL + SEN)
nndd1 <- NnDd(formula = formula, data = dataset, indexes = c("Time","URN","Treated","Outcome"), t_time="0")

Dataset:

school_name URN Treated     Time    Outcome A8  FSM EAL SEN Region
x   xxx 1   -2  91  48.5    27.6    1.6 1.1 North East
y   xxx 1   -2  94  49.3    25.4    67.9    1.1 London
z   xxx 1   -2  96  56.6    18  52.1    1.4 London
william3031
  • 1,401
  • 14
  • 31
Luke
  • 1
  • 1
  • Can you post the dataset in a reproducible way? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Dec 28 '21 at 23:30

0 Answers0