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]
[no subject]
forval y=1990/2000 {
preserve
keep if year==`y'
do coolstuff.do
restore
}
Coolstuff.do is what you are asking about, but it is now going to be
simpler, since it does not have to worry about the time dimension.
Also you don't specify whether the computations with matrices are
symmetric. In other words if you have done your computations with ALB
vs GBR, do you need to do GBR vs ALB?
Best, Sergiy
On Wed, Jul 31, 2013 at 4:39 PM, Jin-Hyun Bae <[email protected]> wrote:
> Hello!
>
> I am doing my first matrix calculation in Stata and it needs to be
> looped for efficiency! I haven't a clue where to start, so I would be
> very grateful for any guidance you can provide.
>
> Here is a toy example.
>
> Country Year CountryY Var1 Var2 Var3
> ALB 1990 ALB1990 38 40 .
> ALB 1991 ALB1991 93 118 .
> ALB 1992 ALB1992 88 51 .
> DZA 1990 DZA1990 241 15 .
> DZA 1991 DZA1991 40 86 .
> ...........
> GBR 1990 GBR1990 67 2 .
> GBR 1991 GBR1991 123 33 .
>
> What I would like requires two nested loops.
>
> At the beginning of loop 1, a matrix (A) with varlist "Var1 Var2" is
> created for the row with GBR1990.
> Then another loop is started, where a similar matrix (B) with varlist
> "Var1 Var2" is created for ALB1990.
> Then follows a matrix calculation involving A, B, and their covariance
> matrix. The resulting scalar is entered as a value of Var3 in the row
> with ALB1990.
> B is then dropped, and the second loop process repeats, with DZA1990.
> After all the Countries with year 1990 are processed, the second loop
> stops and A is dropped.
>
> After this, a new matrix A is created for GBR1991 and a similar
> process repeats.
>
> In the end, Var3 would have missing values only for the rows with
> Country == "GBR".
>
> Jin
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/