hassen62 at voila.fr
2007-Aug-26 20:16 UTC
[R] Program of matrix of seasonal dummy variable(Econometrics)
Dear R users, I would like to construct a matrix of seasonal dummy variables, such matrix can be written as follows(i.e format(T,4)) 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 . . . . . . . . etc I have written the following small program: T=100 br<-matrix(0,T,4) for (i in 1:T) { + for (j in 1:4) { + if i=j {+ br[i,j]=1 + } + if else (abs(i-j)%%4==0) {+ br[i,j]=1 +} + else {+ br[i,j]=0 +} +} +} I have obtained the following message from R consol:> T=100 > br<-matrix(0,T,4) > for (i in 1:T)+ { + + for (j in 1:4) + { + + if i=j Erreur : syntax error, unexpected SYMBOL, expecting '(' dans : " "> > {+ br[i,j]=1+ + } Erreur : syntax error, unexpected '}' dans "{+ br[i,j]=1"> > + if else (abs(i-j)%%4==0)Erreur : syntax error, unexpected ELSE, expecting '(' dans " + if else"> {+ br[i,j]=1+ +} Erreur : syntax error, unexpected '}' dans " {+ br[i,j]=1"> + elseErreur : syntax error, unexpected ELSE dans " + else"> {+ br[i,j]=0+ +} Erreur : syntax error, unexpected '}' dans " {+ br[i,j]=0"> +}Erreur : syntax error, unexpected '}' dans "+}"> +}Erreur : syntax error, unexpected '}' dans "+}">I would require if you can rectify my program in order to obtain this matrix of seasonal dummies. Many thanks in advance. [[alternative HTML version deleted]]
Gabor Grothendieck
2007-Aug-26 20:22 UTC
[R] Program of matrix of seasonal dummy variable(Econometrics)
Try this:> kronecker(rep(1, 3), diag(4))[,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 0 1 0 0 [3,] 0 0 1 0 [4,] 0 0 0 1 [5,] 1 0 0 0 [6,] 0 1 0 0 [7,] 0 0 1 0 [8,] 0 0 0 1 [9,] 1 0 0 0 [10,] 0 1 0 0 [11,] 0 0 1 0 [12,] 0 0 0 1>On 8/26/07, hassen62 at voila.fr <hassen62 at voila.fr> wrote:> Dear R users, > I would like to construct a matrix of seasonal dummy variables, such matrix can be written as follows(i.e format(T,4)) > 1 0 0 0 > 0 1 0 0 > 0 0 1 0 > 0 0 0 1 > 1 0 0 0 > 0 1 0 0 > 0 0 1 0 > 0 0 0 1 > 1 0 0 0 > 0 1 0 0 > 0 0 1 0 > 0 0 0 1 > . . . . > . . . . > etc > I have written the following small program: > T=100 > br<-matrix(0,T,4) > for (i in 1:T) > { > + for (j in 1:4) > { > + if i=j > {+ br[i,j]=1 > + } > + if else (abs(i-j)%%4==0) > {+ br[i,j]=1 > +} > + else > {+ br[i,j]=0 > +} > +} > +} > I have obtained the following message from R consol: > > T=100 > > br<-matrix(0,T,4) > > for (i in 1:T) > + { > + + for (j in 1:4) > + { > + + if i=j > Erreur : syntax error, unexpected SYMBOL, expecting '(' dans : > " > " > > > > {+ br[i,j]=1 > + + } > Erreur : syntax error, unexpected '}' dans "{+ br[i,j]=1" > > > > + if else (abs(i-j)%%4==0) > Erreur : syntax error, unexpected ELSE, expecting '(' dans " + if else" > > {+ br[i,j]=1 > + +} > Erreur : syntax error, unexpected '}' dans " {+ br[i,j]=1" > > + else > Erreur : syntax error, unexpected ELSE dans " + else" > > {+ br[i,j]=0 > + +} > Erreur : syntax error, unexpected '}' dans " {+ br[i,j]=0" > > +} > Erreur : syntax error, unexpected '}' dans "+}" > > +} > Erreur : syntax error, unexpected '}' dans "+}" > > > I would require if you can rectify my program in order to obtain this matrix of seasonal dummies. Many thanks in advance. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >