Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: Use matrix for save results of looping


From   Gonzalo DURAN SANHUEZA <giduran@puc.cl>
To   statalist@hsphsun2.harvard.edu
Subject   st: Use matrix for save results of looping
Date   Sun, 30 Sep 2012 12:15:42 -0300

Dear Statalist-Members, by each database, I want save one scalar in a
unique matrix. I use a foreach command for load each database. The
problem with my instruction is that only retrieves the scalar for the
latest database. I need two things: 1) a unique matrix that retrieves
the scalars defined in all the loop and 2) if exist some instruction
for   export the matrix into a csv file. Thanks

This is the do

clear all
set mem 800m
global path="E:\data\ENE"
global pathdo="C:\gonzalo\"
cd "${path}"
local bases ond1996 ond1997

foreach base of local bases {
   if "`base'"=="ond1996" {
      use ond1996, clear
   }
   if "`base'"=="ond1997" {
      use ond1997, clear
   }
summ p12_2 if p12_2>48
local hora=r(sum_w)
summ estado if estado==1
scalar k=round(`hora'/r(sum_w)*100, .1)
matrix define P=(k)
matrix rowname P=`base'
matrix colname P=Junior
matrix list P
}
*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index