[R] plm Hausman-Taylor model
Achim Zeileis
Achim.Zeileis at wu-wien.ac.at
Sat Apr 25 22:31:38 CEST 2009
On Sat, 25 Apr 2009, Ron Burns wrote:
> Dear all-
>
> I am have trouble in using the model="ht" option in function plm from the plm
> library. I am using
> Package: plm Version: 1.1-1; R version 2.8.1 (2008-12-22) running on a FC-8
> linux machine.
>
> Here is what I am trying to do:
>
> ##----------------------------------------------------------------------------
> R> ###Prob 6 Chapter 3 Use R! Applied Econometrics with R (Kleiber &
> Zeileis)
> R> ## hlp(PSID1982) => cross section data for 1982 only Need panel data I
> guess
> R> ## found full set on STATA web site
> R> ## http://www.stata-press.com/data/r10/psidextract.dta
> R> ## STATA results in Sec 2 of: folk.uio.no/erikbi/ECON5120_H07_Note19.pdf
> R> library("foreign")
> R> fulldat <- read.dta("~/Desktop/psidextract.dta")
> R> library("plm")
> R>
> R> fulldat.plm = plm.data(fulldat,index=c("id","t"))
> R>
> R> earn_plm <- plm(lwage~ occ+ south+ smsa+ ind+ exp+ exp2+ wks+
> + ms+ union+ fem+ blk+ ed | exp+ exp2+ wks+ ms+ union+ ed,
> + data = fulldat.plm,model="ht")
> Error in names(result) <- nf : attempt to set an attribute on NULL
>
> I have tried several variations and some other data sets (not so easily
> reproducible for others as this one) but have yet to obtain an error free
> result.
This seems to be a bug in "plm". traceback() shows:
R> traceback()
4: lev2var(data[, -c(K - 1, K)])
3: plm.ht(formula, data)
2: switch(model, within = plm.within(formula, data, effect), between =
plm.between(formula,
data, effect), pooling = plm.pooling(formula, data), random =
plm.random(formula,
data, effect, random.method, inst.method), ht = plm.ht(formula,
data), fd = plm.fd(formula, data))
1: plm(lwage ~ occ + south + smsa + ind + exp + exp2 + wks + ms +
union + fem + blk + ed | exp + exp2 + wks + ms + union +
ed, data = fulldat.plm, model = "ht")
lev2var() is a function internal to "plm" and it apparently fails if there
are no factors in the data. (The result is NULL and lev2var() tries to
assign names to it; these are character(0) but still this fails with the
error message you have quoted above.) Maybe Yves can clarify this.
A workaround for your example is to code the dummy variables as factors
(which might also be more useful in other situations). For example:
R> for(i in c(3:9, 11)) fulldat[[i]] <- factor(fulldat[[i]])
R> fulldat.plm = plm.data(fulldat,index=c("id","t"))
R> earn_plm <- plm(lwage~ occ+ south + smsa+ ind + exp + exp2 + wks +
+ ms + union + fem + blk + ed | exp + exp2 + wks + ms + union + ed,
+ data = fulldat.plm, model = "ht")
Of course, more meaningful factor levels would be desirable but at least
this works. It gives similar results to those that you refer to above, but
they are not identical. Maybe Yves can something more about the
differences to Stata.
hth,
Z
> Thanks in advance for any help
> Ron
> --
> R. R. Burns
> Retired
> Oceanside, CA
>
>
>
More information about the R-help
mailing list