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: Use matrix for save results of looping
From
Gonzalo DURAN SANHUEZA <[email protected]>
To
[email protected]
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/