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 on April 23, and its replacement, 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 <>
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:

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