Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: patterned matrix creation


From   "Lachenbruch, Peter" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: patterned matrix creation
Date   Fri, 10 Sep 2010 09:52:11 -0700

Dear Statalisters,

I want to create a matrix of the form in order to create running sums of 3 observations.  Note that the last 2 rows recycle times 1 and 2.  (This is to create sums of events in each of 12 months).

M[12,12]
      c1   c2   c3   c4   c5   c6   c7   c8   c9  c10  c11  c12
 r1    1    1    1    0    0    0    0    0    0    0    0    0
 r2    0    1    1    1    0    0    0    0    0    0    0    0
 r3    0    0    1    1    1    0    0    0    0    0    0    0
 r4    0    0    0    1    1    1    0    0    0    0    0    0
 r5    0    0    0    0    1    1    1    0    0    0    0    0
 r6    0    0    0    0    0    1    1    1    0    0    0    0
 r7    0    0    0    0    0    0    1    1    1    0    0    0
 r8    0    0    0    0    0    0    0    1    1    1    0    0
 r9    0    0    0    0    0    0    0    0    1    1    1    0
r10    0    0    0    0    0    0    0    0    0    1    1    1
r11    1    0    0    0    0    0    0    0    0    0    1    1
r12    1    1    0    0    0    0    0    0    0    0    0    1

I entered this one manually - it's obviously prone to my own errors.  I would like to be able to do this easily with the matrix command J(r,s,z).  I can do this as a start with
matrix A=(J(3,1,1)\J(9,1,0))'
matrix A1=(0\J(3,1,1)\J(8,1,0))'
and then concatenating.  
I'd like to write a simple foreach (or forval) loop for this.  I'm blanking on this - probably a result of old age and the beginning of the school year...
Any quick ideas?  
It would be nice to be able to choose the sum length as 2 or 4 or 6, etc. 


Tony

Peter A. Lachenbruch
Department of Public Health
Oregon State University
Corvallis, OR 97330
Phone: 541-737-3832
FAX: 541-737-4001



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index