Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Adding Matrices generated from a loop


From   "Nadeem Shafique" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Adding Matrices generated from a loop
Date   Mon, 27 Aug 2007 18:10:41 +0500

Respected Nick Cox,

Thank you so much, only with your though provoking ideas I am able to
complete my task. May God increase your knowledge.

Best Regards,

Nadeem

On 8/24/07, Nick Cox <[email protected]> wrote:
> Perhaps I should add that initialising the sum matrix
> to be zeros can be best. Initialising the sum matrix
> to be the first matrix is not, of course, the only
> way to do it.
>
> Nick
> [email protected]
>
> Nick Cox
>
> > Well, initialise outside the loop, and add each replaced
> > t_i to the sum so far each time round the loop. Naturally,
> > all the matrices must be conformable.
> >
> > Nick
> > [email protected]
> >
> > Nadeem Shafique
> >
> > > Sorry for not providing complete information, I am trying it using
> > > Mata. Following is the code i am trying to execute.
> > >
> > > **************************************************************
> > > ******************************
> > >   for (i=1; i<=rows(info); i++)
> > >                                     {
> > >
> >      v_i =
> > > panelsubmatrix(v, i, info)
> > >                             m_i = panelsubmatrix(m,i,info)
> > >                             n_i = panelsubmatrix(s,i,info)
> > >                             n = mean(n_i)
> > >                             t_i=v_i*m_i*n
> > >
> > >                     }
> > >
> > > ****************** I want to sum all these t_i in one matrix say "t"
> >
> >
> > > On 8/24/07, Nick Cox <[email protected]> wrote:
> > > > There may be subtleties here I am missing, but
> > > > I would initialise
> > > >
> > > >        sum <- first_matrix
> > > >
> > > > and then loop over the other matrices
> > > >
> > > >        sum <- sum + next_matrix
> > > >
> > > > This is pseudocode.
> > > >
> > > > Otherwise I can't tell what's troubling you about
> > > > this. As the details will depend on whether
> > > > you are using Stata or Mata, your naming structure,
> > > > what else you are doing with these matrices,
> > > > whether the number is predictable in advance, etc.,
> > > > none of which is indicated, I'll leave it there.
> >
> > > > Nadeem Shafique
> > > >
> > > > > I want to add several matrices (say K) of the same order,
> > > suppose the
> > > > > matrices to be added are comming from a loop, how can i
> > > calculate the
> > > > > following
> > > > >
> > > > >                 K
> > > > >                 Sum    X_i
> > > > >                 i=1
> > > > > where X_i is the ith Matix
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>


-- 
Nadeem Shafique Butt
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index