Oh Dong-hyun
2008-Jun-14 12:49 UTC
[R] restricted coefficient and factor in linear regression.
Hi, my data set is data.frame(id, yr, y, l, e, k). I would like to estimate Lee and Schmidts (1993, OUP) model in R. My colleague wrote SAS code as follows: ** procedures for creating dummy variables are omitted ** ** di# and dt# are dummy variables for industry and time ** data a2; merge a1 a2 a; by id yr; proc sysnlin maxit=100 outest=beta2; endogenous y; exogenous l e k di1-di12 dt2-dt10; parms a0 0.94 al -0.14 ae 1.8 ak -0.9 b1 0 b2 0 b3 0 b4 0 b5 0 b6 0 b7 0 b8 0 b9 0 b10 0 b11 0 b12 0 c2 0 c3 0 c4 0 c5 0 c6 0 c7 0 c8 0 c9 0 c10 0; y=a0+al*l+ae*e+ak*k +(b1*di1+b2*di2+b3*di3+b4*di4+b5*di5+b6*di6 +b7*di7+b8*di8+b9*di9+b10*di10+b11*di11+b12*di12)* (1*dt1+c2*dt2+c3*dt3+c4*dt4+c5*dt5+c6*dt6+c7*dt7 +c8*dt8+c9*dt9+c10*dt10); title '***** lee/schmidt parameter estimates *****'; My R code is as follows: ############## library(plm) dt <- read.table("dt.dta", sep = "\t", header= T) dt$id <- factor(dt$id) dt$yr <- factor(dt$yr) fit.model <- I(log(y)) ~ I(log(l)) + I(log(e)) + yr * id re.fit.gls <- pggls(fit.model, data = dt) ################# I've got the following error message: ##### Error message ############### Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent #### End of Error message############ I would like to figure out three things. 1. How can I restrict coefficient in model? As you can see in SAS code, coefficient of dt1 is restricted to 1. 2. If it is possible to restrict coefficients, it is possible to restrict coefficients of factors? If so, how? Thanks in advance. Best,
Paul Johnson
2008-Jun-15 19:14 UTC
[R] restricted coefficient and factor in linear regression.
On Sat, Jun 14, 2008 at 7:49 AM, Oh Dong-hyun <oh.dongh at gmail.com> wrote:> Hi, > > my data set is data.frame(id, yr, y, l, e, k). > > I would like to estimate Lee and Schmidts (1993, OUP) model in R. > > My colleague wrote SAS code as follows: > ** procedures for creating dummy variables are omitted ** > ** di# and dt# are dummy variables for industry and time ** > data a2; merge a1 a2 a; by id yr; > proc sysnlin maxit=100 outest=beta2; > endogenous y; > exogenous l e k di1-di12 dt2-dt10; > parms a0 0.94 al -0.14 ae 1.8 ak -0.9 > b1 0 b2 0 b3 0 b4 0 b5 0 b6 0 b7 0 b8 0 b9 0 b10 0 b11 0 > b12 0 c2 0 c3 0 c4 0 c5 0 c6 0 c7 0 c8 0 c9 0 c10 0; > y=a0+al*l+ae*e+ak*k > +(b1*di1+b2*di2+b3*di3+b4*di4+b5*di5+b6*di6 > +b7*di7+b8*di8+b9*di9+b10*di10+b11*di11+b12*di12)* > (1*dt1+c2*dt2+c3*dt3+c4*dt4+c5*dt5+c6*dt6+c7*dt7 > +c8*dt8+c9*dt9+c10*dt10); > title '***** lee/schmidt parameter estimates *****'; > > My R code is as follows: > ############## > library(plm) > dt <- read.table("dt.dta", sep = "\t", header= T) > dt$id <- factor(dt$id) > dt$yr <- factor(dt$yr) > fit.model <- I(log(y)) ~ I(log(l)) + I(log(e)) + yr * id > re.fit.gls <- pggls(fit.model, data = dt) > ################# > > I've got the following error message: > ##### Error message ############### > Error in dimnames(x) <- dn : > length of 'dimnames' [2] not equal to array extent > #### End of Error message############ > > I would like to figure out three things. > 1. How can I restrict coefficient in model? As you can see in SAS code, > coefficient of dt1 is restricted to 1. > 2. If it is possible to restrict coefficients, it is possible to restrict > coefficients of factors? If so, how? >Hello, I've not used the package plm very much. I've been reading its docs now and I don't think it is exactly what you want, since you've not described a panel data problem. Possibly you need to take this up with the plm author. If I were you, I'd go in another direction. First, fit with ordinary 'lm', just to check sanity of data. Second, get the package "systemfit" in which there is a nonlinear system fitting routine comparable to the SAS sysnlin that your colleague is using. Let us know how it works out. -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas