[R] I need intercept in plm model

368 views
Skip to first unread message

matteo ognibene

unread,
Dec 29, 2012, 8:47:33 AM12/29/12
to r-h...@r-project.org

Hi,R 2.15.2 plm() function on Windows 7
when i perform a plm regression, i can't manage to obtain the intercept, but I need it.it gives me just the beta coefficient.
my formula: fixed <- plm(deltaS ~ L1.deltaS + L2.deltaS, data=Mody_R, index=c("country_id", "date"), model="within")
my output: Coefficients : Estimate Std. Error t-value Pr(>|t|) L1.deltaS -0.063576 0.017950 -3.5419 0.0004031 ***L2.deltaS -0.068272 0.017966 -3.8001 0.0001474 ***---
I tried adding "-0", "+1", "intercept=TRUE"
Thanks,Matteo
[[alternative HTML version deleted]]

______________________________________________
R-h...@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.

Millo Giovanni

unread,
Dec 31, 2012, 6:20:59 AM12/31/12
to ogniben...@hotmail.it, r-h...@r-project.org

Dear Matteo,

a fixed effects (within) model does not have a single intercept: it has
N. I suggest you have another look at FE models' theory.

Some confusion often stems from Stata (misleadingly, IMHO) reporting an
"intercept" which is actually the average of the individual intercepts,
which you can recover in R as 'mean(fixef(<yourmodel>))'. Remember,
though, that this isn't "the intercept" of the estimated model in the
usual sense of the term. If you "need" an intercept, then you must
review your specification.

Best,
Giovanni

--------------- original message
-------------------------------------------------------

Message: 1
Date: Sat, 29 Dec 2012 14:47:33 +0100
From: matteo ognibene <ogniben...@hotmail.it>
To: <r-h...@r-project.org>
Subject: [R] I need intercept in plm model
Message-ID: <DUB105-W4934C48C7...@phx.gbl>
Content-Type: text/plain


Hi,R 2.15.2 plm() function on Windows 7
when i perform a plm regression, i can't manage to obtain the intercept,
but I need it.it gives me just the beta coefficient.
my formula: fixed <- plm(deltaS ~ L1.deltaS + L2.deltaS, data=Mody_R,
index=c("country_id", "date"), model="within")
my output: Coefficients : Estimate Std. Error t-value
Pr(>|t|) L1.deltaS -0.063576 0.017950 -3.5419 0.0004031
***L2.deltaS -0.068272 0.017966 -3.8001 0.0001474 ***---
I tried adding "-0", "+1", "intercept=TRUE"
Thanks,Matteo
[[alternative HTML version deleted]]

------------- end original message -----------------

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

matteo ognibene

unread,
Jan 3, 2013, 11:19:23 AM1/3/13
to r-h...@r-project.org

Hi,R 2.15.2 plm() function on Windows 7
I have a problem with the variance estimation in a random effect model
I used this formula to get my result, and it works:reg <- deltaF ~ L1.deltaF + L2.deltaF + deltaCDS + L1.deltaCDS + L2.deltaCDS + L3.deltaCDS + deltaUS_Yields + deltaZ + L1.deltaZ + L2.deltaZfixed <- plm(reg, data=Mody_R, na.action = na.exclude, index=c("country_id", "datestata"), model="random")
but when i split my dataframe into several groups it gives me this error:"Error in swar(object, data, effect) : the estimated variance of the individual effect is negative"
The code i used to split the dataframe is:SplitMody <- split(Mody_R, Mody_R$period)SplitFixed <- lapply(SplitMody, function(Mody_R) plm(reg, data=Mody_R, na.action = na.exclude, index=c("country_id", "datestata"), model="random"))
I want to point the all the code works perfectly in a within model, and I tried using all the random.method for the variance estimation.In addition I used the same model in Stata and it works... (the results are identical for a within model in R and Stata)
I'll be really gratefull if someone can help me.

David Winsemius

unread,
Jan 3, 2013, 4:23:07 PM1/3/13
to matteo ognibene, r-h...@r-project.org

On Jan 3, 2013, at 8:19 AM, matteo ognibene wrote:

>
> Hi,R 2.15.2 plm() function on Windows 7
> I have a problem with the variance estimation in a random effect model
> I used this formula to get my result, and it works:reg <- deltaF ~
> L1.deltaF + L2.deltaF + deltaCDS + L1.deltaCDS + L2.deltaCDS +
> L3.deltaCDS + deltaUS_Yields + deltaZ + L1.deltaZ + L2.deltaZfixed
> <- plm(reg, data=Mody_R, na.action = na.exclude,
> index=c("country_id", "datestata"), model="random")
> but when i split my dataframe into several groups it gives me this
> error:"Error in swar(object, data, effect) : the estimated
> variance of the individual effect is negative"
> The code i used to split the dataframe is:SplitMody <- split(Mody_R,
> Mody_R$period)SplitFixed <- lapply(SplitMody, function(Mody_R)
> plm(reg, data=Mody_R, na.action = na.exclude, index=c("country_id",
> "datestata"), model="random"))
> I want to point the all the code works perfectly in a within model,
> and I tried using all the random.method for the variance
> estimation.In addition I used the same model in Stata and it
> works... (the results are identical for a within model in R and Stata)
> I'll be really gratefull if someone can help me.
> Thanks,Matteo
> [[alternative HTML version deleted]]

Head up; matteo: This is pretty much unreadable (due to the failure to
follow the recommended posting procedure.)

--
David Winsemius, MD
Alameda, CA, USA

matteo ognibene

unread,
Jan 4, 2013, 7:10:22 AM1/4/13
to dwins...@comcast.net, r-h...@r-project.org

You're right David, I'm really sorry. I deactivated html, hope now it works.


> R 2.15.2 plm() function on Windows 7.
I have a problem with the variance estimation in a random effect model


I used this formula to get my result, and it works:
> reg <- deltaF ~ L1.deltaF + L2.deltaF + deltaCDS + L1.deltaCDS + L2.deltaCDS + L3.deltaCDS + deltaUS_Yields + deltaZ + L1.deltaZ.
> fixed <- plm(reg, data=Mody_R, na.action = na.exclude, index=c("country_id", "datestata"), model="random").


but when i split my dataframe into several groups it gives me this error:
> "Error in swar(object, data, effect) : the estimated variance of the individual effect is negative"


The code i used to split the dataframe is:
> SplitMody <- split(Mody_R, Mody_R$period).
> SplitFixed <- lapply(SplitMody, function(Mody_R) plm(reg, data=Mody_R, na.action = na.exclude, index=c("country_id", "datestata"), model="random")).


I want to point the all the code works perfectly in a within model, and I tried using all the random.method for the variance estimation.
In addition I used the same random effect model in Stata and it works... (and for the within model the results are identical in R and Stata)


I'll be really gratefull if someone can help me.


Thanks,
Matteo

> CC: r-h...@r-project.org
> From: dwins...@comcast.net
> To: ogniben...@hotmail.it
> Subject: Re: [R] plm random effect: the estimated variance of the individual effect is negative
> Date: Thu, 3 Jan 2013 13:23:07 -0800

Millo Giovanni

unread,
Jan 4, 2013, 10:26:01 AM1/4/13
to ogniben...@hotmail.it, r-h...@r-project.org
Matteo,

I fully agree with David: please read the posting guide.

Anyway, the error message says it all: "the estimated variance of the
individual effect is negative". See e.g. the "basic panel" chapter (10
or 11) in Wooldridge's "Econometric Analysis of XS and Panel Data" to
understand why this may happen.

Stata's behaviour is (as far as I remember) to transparently substitute
it with 0; 'plm's is to let the estimation fail, issuing a warning. You
can try a different 'random.method' which may, or might not, solve the
problem, depending on your data.

Hint: a random effects model with sigma_mu=0 is a pooling model.

HTH

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

------------ original message ------------------

Message: 49


Date: Thu, 3 Jan 2013 13:23:07 -0800

From: David Winsemius <dwins...@comcast.net>
To: matteo ognibene <ogniben...@hotmail.it>
Cc: "r-h...@r-project.org" <r-h...@r-project.org>


Subject: Re: [R] plm random effect: the estimated variance of the
individual effect is negative

Message-ID: <D32FDC11-38AE-4AAF...@comcast.net>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

> [[alternative HTML version deleted]]

--------------- end original message ---------------

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

______________________________________________

matteo ognibene

unread,
Jan 4, 2013, 2:08:09 PM1/4/13
to giovann...@generali.com, r-h...@r-project.org

Thanks Giovanni,

but I already tried with the others "random.method" and it doesn't work anyway.
Do you think is it possible change the if statement in the plm formula, to set the value to 0 if sigma<0 ?
Because if I insert a dummy variabile in the formula R gives me this error:

> Error in if (sigma2$id < 0) stop(paste("the estimated variance of the",  : 
>             missing value where TRUE/FALSE needed

Thanks
Matteo Ognibene


----------------------------------------
> Subject: Re: [R] plm random effect: the estimated variance of the individual effect is negative
> Date: Fri, 4 Jan 2013 16:26:01 +0100
> From: Giovann...@Generali.com
> To: ogniben...@hotmail.it
> CC: r-h...@r-project.org
> Ai sensi del D.Lgs. 196/2003 si precisa che le informazioni contenute in questo messaggio sono riservate ed a uso esclusivo del destinatario. Qualora il messaggio in parola Le fosse pervenuto per errore, La invitiamo ad eliminarlo senza copiarlo e a non inoltrarlo a terzi, dandocene gentilmente comunicazione. Grazie.
>
> Pursuant to Legislative Decree No. 196/2003, you are hereby informed that this message contains confidential information intended only for the use of the addressee. If you are not the addressee, and have received this message by mistake, please delete it and immediately notify us. You may not copy or disseminate this message to anyone. Thank you.

Millo Giovanni

unread,
Jan 5, 2013, 4:10:01 AM1/5/13
to matteo ognibene, r-h...@r-project.org
Dear Matteo,
as I stated in my previous email, if the random effects variance is set to zero then they are identically zero (as mean=0, sd=0) hence you just need to use 'plm(<...> , model="pooling")'.
Best,
Giovanni

-----Messaggio originale-----
Da: matteo ognibene [mailto:ogniben...@hotmail.it]
Inviato: venerdì 4 gennaio 2013 20.08
A: Millo Giovanni; r-h...@r-project.org
Oggetto: RE: [R] plm random effect: the estimated variance of the individual effect is negative
> > Hi,R 2.15.2 plm() function on Windows 7 I have a problem with the
Reply all
Reply to author
Forward
0 new messages