Statalist The Stata Listserver


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

st: for loop


From   Steven Gorl� <[email protected]>
To   <[email protected]>
Subject   st: for loop
Date   Thu, 11 Jan 2007 23:58:05 +0100

Dear Stata experts,

How can I append the results of my for loop in a file "sample"?

I would like to store the summary results of each i loop in a datafile sample.

Unfortunately the loop overwrites sample.

I would like to keep 4 variables gem se sd a.

Below you will find the syntax.

Any tips are welcome,



Thanks in advance !!!

Steven Gorle



Syntax:

forvalues i=1/100 {

use bmi_voeg, clear

sample 200, count

gen pw = 8564/200

gen fpc = 8564

summarize lnvoeg

generate gem = r(mean)

generate sd = r(sd)

generate a = r(N)

generate se = sd/(sqrt(a))

display "gem " gem " " "sd " sd " " "se " se " " "a " a

collapse gem sd se a

save sample

}








*
* 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