Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Efficient use of -postfile-


From   "Mentzakis, Emmanouil" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: Efficient use of -postfile-
Date   Tue, 17 Jun 2008 20:56:52 +0100

Dear all,

I am trying to transfer some results into a new dataset using -postfile- but I am not sure I am doing it in a very efficient way.

Although the code is running fine with the example dataset, I am sure it could be improved (and maybe avoid potential problems that I haven't even thought of).

Could anybody please offer any advice?

Thank you in advance
Manos


******************* Example code ******************
webuse intregxmpl, clear

intreg wage1 wage2
predict pr, pr(wage1, wage2)
egen rm=rowmean(wage1 wage2) if e(sample)

tempname A B
tempfile gr1 gr2 graphs

postfile `A' str8 pr using `gr1', replace
levelsof pr
local lev "`r(levels)'"
foreach i of local lev {
        post `A' ("`i'")
}
postclose `A'

postfile `B' str8 rm using `gr2', replace
levelsof rm
local lev "`r(levels)'"
foreach i of local lev {
        post `B' ("`i'")
}
postclose `B'

use `gr1', clear
destring, replace
gen n=_n
sort n
save , replace
use `gr2', clear
destring, replace
gen n=_n
sort n
save , replace

use `gr1', clear
merge n using `gr2'
drop _merge
save `graphs', replace



The University of Aberdeen is a charity registered in Scotland, No SC013683.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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