[R] Program of matrix of seasonal dummy variable(Econometrics)

2007-08-26 Thread hassen62
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))
10   0   0
01   0   0
00   1   0
00   0   1
10   0   0
01   0   0
00   1   0
00   0   1
10   0   0
01   0   0
00   1   0
00   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@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.


Re: [R] Program of matrix of seasonal dummy variable(Econometrics)

2007-08-26 Thread Gabor Grothendieck
Try this:

 kronecker(rep(1, 3), diag(4))
  [,1] [,2] [,3] [,4]
 [1,]1000
 [2,]0100
 [3,]0010
 [4,]0001
 [5,]1000
 [6,]0100
 [7,]0010
 [8,]0001
 [9,]1000
[10,]0100
[11,]0010
[12,]0001



On 8/26/07, [EMAIL PROTECTED] [EMAIL PROTECTED] 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))
 10   0   0
 01   0   0
 00   1   0
 00   0   1
 10   0   0
 01   0   0
 00   1   0
 00   0   1
 10   0   0
 01   0   0
 00   1   0
 00   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@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.


__
R-help@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.