# First, make a pdata.frame
data(Grunfeld)
pGrunfeld <- pdata.frame(Grunfeld)
# then make a model frame from a pFormula and a pdata.frame
pform <- pFormula(inv ~ value + capital)
mf <- model.frame(pform, data = pGrunfeld)
# construct (transformed) response of the within model
resp <- pmodel.response(pform, data = mf, model = "within")
# retrieve (transformed) response directly from model frame
resp_mf <- pmodel.response(mf, model = "within")
# retrieve (transformed) response from a plm object, i.e. an estimated model
fe_model <- plm(pform, data = pGrunfeld, model = "within")
pmodel.response(fe_model)
# same as constructed before
all.equal(resp, pmodel.response(fe_model), check.attributes = FALSE) # TRUE
Run the code above in your browser using DataLab