Statalist


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

st: AW: Saving results


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Saving results
Date   Sat, 10 Oct 2009 17:02:26 +0200

<> 



*************
/*
construct dataset 
*/ 
clear*
inp byte(state)
6
8
10
end

//fixed effect per state from std normal
gen alpha=rnormal()
//# of years: 11, starting 1990
expand 11
bys state: gen year=_n+1989
//number of persons per state and year:50
expand 50
bys state year: gen individual=_n
//income DGP
gen income=10+rchi2(3)+alpha

compress
list, sepby(state) noo

/*
get and store results 
*/ 
tempname hdle
capt erase info.dta

postfile `hdle' state year gini using info

qui foreach s in 6 8 10 {
  forval i = 1990/2000 {
    fastgini income if state == `s' & year == `i'
    post `hdle' (`s') (`i') (r(gini))
  }
}

postclose `hdle'

use info, clear
l, noo sepby(state)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von John Pfaff
Gesendet: Samstag, 10. Oktober 2009 16:34
An: statalist@hsphsun2.harvard.edu
Betreff: st: Saving results

Hello,

I have a question about saving individual results while running a loop. I'm
trying to compute the annual state-level gini coefficient across several
states and years, using fastgini. The basic command (in practice, I have a
lot more states and years) is:

foreach s in 6 8 10 {
     forval i = 1990(1)2000 {
       fastgini var1 if state == `s' & year == `i'
     }
}

(Since fastgini doesn't support "by," I can't run "fastgini var1, by(state
year)" and get a table of results.)

What I want to produce is a file that has a column for state, a column for
year, and a column for the gini output. So I figure I need to put something
after the "fastgini var1" line to save each output, but I'm not sure what.
Ideally, I'd like to be able to save each iteration to the same file, just
appending each new iteration to the end of the file. But I could also save
each output to a separate file and append them all at the end.

Some fastgini-specific features that could be helpful:

Running fastgini produces an output like this:

. fastgini var1
gini coefficient = 0.707707707707

According to the .hlp file, fastgini's output is stored in r().

Thanks for any suggestions!

John

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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