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]

From |
Anna Reimondos <areimondos@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Mata looping question |

Date |
Tue, 18 Oct 2011 21:09:01 +1100 |

Hi Maarten Thanks very much for the reply that is very helpful..however I was hoping to shift the elements across the columns the other way if that makes sense. E.g. if matrix a is: c1 c2 c3 r1 1 0 0 r2 0 2 1 r3 0 1 0 r4 0 0 0 then matrix b I want to look like: c1 c2 c3 r1 2 1 . r2 1 0 . r3 0 0 . r4 . . . (To give a bit of context, the data I am working with has ages of women in the row e.g. 15, 16...45 and number of children at different ages e.g. 0,1,2,...15 in the columns . I am reverse ageing the data. So at r2,c2 it means in year T a woman aged 16 had 2 children aged 2. The b matrix is trying to get at year T-1. In that case she was 15 and had 2 children aged 1) Cheers Anna On Tue, Oct 18, 2011 at 8:54 PM, Maarten Buis <maartenlbuis@gmail.com> wrote: > On Tue, Oct 18, 2011 at 11:37 AM, Anna Reimondos wrote: >> For example if I have one original matrix called 'a' >> >> matrix a=(1,0,0\0,2,1\0,1,0\0,0,0) >> matrix list a >> >> I then want to create another matrix 'b' which is equal to 'a' but >> where every element has been shifted up one row and across one column. > > I would not do that with a loop: > > *------------- begin example ---------------- > mata > a=(1,0,0\0,2,1\0,1,0\0,0,0) > b = J(5,1,0), (a \ J(1,3,0)) > b > end > *----------- end example ---------------- > (For more on examples I sent to the Statalist see: > http://www.maartenbuis.nl/example_faq ) > > Hope this helps, > Maarten > > -------------------------- > Maarten L. Buis > Institut fuer Soziologie > Universitaet Tuebingen > Wilhelmstrasse 36 > 72074 Tuebingen > Germany > > > http://www.maartenbuis.nl > -------------------------- > * > * 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/ > * * 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/

**Follow-Ups**:**RE: st: Mata looping question***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: Mata looping question***From:*Anna Reimondos <areimondos@gmail.com>

**Re: st: Mata looping question***From:*Maarten Buis <maartenlbuis@gmail.com>

- Prev by Date:
**st: Ask for OLS and panel code for analysis between different periods** - Next by Date:
**Re: st: Ask for OLS and panel code for analysis between different periods** - Previous by thread:
**Re: st: Mata looping question** - Next by thread:
**RE: st: Mata looping question** - Index(es):