[R] Attribute Length Error when Trying plm Regression

Millo Giovanni Giovanni_Millo at Generali.com
Thu Sep 5 14:06:01 CEST 2013


Dear Laura,

as Arun said it is difficult to help w/o a reproducible example. However
this is most likely to be an indexing problem, as he suggests; the
output of traceback() is far from useless here, because it shows that
the problem occurs in the data transformation step. The latter, which is
by default the within transf., wants (correct indexing and-) time
variation in the data. Hence I suggest you 
- better check the data, especially indices, possibly with str() to see
if they have the right type etc.
then do simpler things, complicating step by step until you spot the
critical one:
- try lm(yourformula, yourdata) to see whether there are data problems
w.r.t. OLS (unlikely, but would spot string variables or other common
pitfalls)
- try pdata.frame() using the individual and time index, to spot if the
indices are somehow inappropriate
- try plm(... , model="pooling"), which does not transform the data, or
model="random", which allows for time-invariants; both are more tolerant
than "within"

This is most likely either bad indices or bad data formats/NAs/empty
groups...

Best wishes,
Giovanni

Giovanni Millo, PhD
Research Dept.,
Assicurazioni Generali SpA
Via Machiavelli 3,
34132 Trieste (Italy)
tel. +39 040 671184
fax  +39 040 671160


------------ Original thread ------------------

Message: 48
Date: Wed, 4 Sep 2013 14:14:23 -0700 (PDT)
From: arun <smartpink111 at yahoo.com>
To: lross8 <lross8 at kent.edu>
Cc: R help <r-help at r-project.org>
Subject: Re: [R] Attribute Length Error when Trying plm Regression
Message-ID:
	<1378329263.73618.YahooMailNeo at web142604.mail.bf1.yahoo.com>
Content-Type: text/plain; charset=iso-8859-1

HI,
It is better to provide a reproducible example using ?dput().
you can also check in this link.

http://r.789695.n4.nabble.com/names-attribute-must-be-the-same-length-as
-the-vector-td4503946.html

library(plm)
#Using the example from ?plm()
?data("Produc", package = "plm")
?zz <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data =
Produc, index = c("state","year"))

#Suppose, if I use a model like this:
zz1<-
plm(gsp~pcap+pc+emp+unemp+water+util,data=Produc,index=c("gsp","year"))
#Error in names(y) <- namesy : 
?# 'names' attribute [816] must be the same length as the vector [0]

In your model statement, 

fixed <- plm (h ~ o + m + a, data=drugsXX, index=c("h","year"),
model="within") 


A.K.


----- Original Message -----
From: lross8 <lross8 at kent.edu>
To: r-help at r-project.org
Cc: 
Sent: Wednesday, September 4, 2013 3:22 PM
Subject: [R] Attribute Length Error when Trying plm Regression

Hello,

I am trying to run a fixed effects panel regression on data containing 5
columns and 1,494 rows. 

I read the data in as follows:

>drugsXX<-read.csv(file="C:\\Folder\\vX.X\\Drugs\\drugsXX_panel.csv",
head=TRUE, sep=",")

Verified it read in correctly and had a good data.frame:
>dim(drugsXX)
[1] 1494? ? 5
>drugs XX
produce expected data with correct column names

The issue is, when I go to run the plm using:
>fixed <- plm (h ~ o + m + a, data=drugsXX, index=c("h","year"),
model="within") 

I get this error:
Error in names(y) <- namesy : 
? 'names' attribute [996] must be the same length as the vector [0]

I know the data recognizes that I have 5 columns. I also know that
there's
nothing wrong with row 996 (I even want back and checked for hidden
characters in the original .csv file).

traceback() was useless:
4: pmodel.response.pFormula(formula, data, model = model, effect =
effect, 
? ? ?  theta = theta)
3: pmodel.response(formula, data, model = model, effect = effect, 
? ? ?  theta = theta)
2: plm.fit(formula, data, model, effect, random.method, inst.method)
1: plm(h ~ o + m + a, data = drugsXX, index = c("h", 
? ? ?  "year"), model = "within")

What explicit steps can I follow to get my panel regression to run? 

Thank you, 
Laura



--
View this message in context:
http://r.789695.n4.nabble.com/Attribute-Length-Error-when-Trying-plm-Reg
ression-tp4675384.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

------------- end original thread --------------

 
Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:12}}



More information about the R-help mailing list