Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: Re: Efficienct ?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: Re: Efficienct ?
Date   Wed, 14 May 2003 15:48:21 +0100

victor michael zammit

> given a dataset with 100 variables,of five observations in 
> each,where the
> 5th observation goes from 1 to 100, e.g. :
> 
> 
>   a1 a2..... a50...... a100
>   1 1 1 1
>   2 2 2 2
>   3 3 3 3
>   4 4 4 4
>   1 2 50 100
> The dataset is saved as A1toA100
>  I would like to postfile the  standard error,the lower 
> bound and the upper
> bound  for each variable,at 95% confidence.I am using Stata 
> 6.0.What I am
> doing is this case is to program the following ,with the  
> ensuing result:
> 
> quietly {
> capture program drop pstfle
> program define pstfle
> use A1toA100,clear
> keep A`1'
> quietly ci
> di r(se)    "     " r(lb) "   " r(ub)
> end
> }
> pstfle  1
> pstfle 2
> pstfle 50
> pstfle 100
> 
> 
> . pstfle  1
> .58309519     .58106823   3.8189318
> 
> . pstfle 2
> .50990195     .98428524   3.8157148
> 
> . pstfle 50
> 9.5131488     -14.412735   38.412735
> 
> . pstfle 100
> 19.506409     -32.158474   76.158474
> 
> After highlight "copy"  and "paste" ,I use "edit" the data 
> in a variables'
> format.
> Is there a more efficient way of doing this ?

I am not clear where you want the results to go. 

Although you refer to postfile your code just 
displays results in Stata and has no connection 
to the -postfile- command. No problem there, 
except that the word is a keyword to Stata people. 

You could do just this: 

(1) 

use A1toA100 

local i = 1 
while `i' <= 100 { 
	qui ci a`i' 
	di r(se)    "     " r(lb) "   " r(ub)
	local i = `i' + 1 
} 

I think that should work in Stata 6. 

Or you could do this: 

(2) 

use A1toA100
set obs 100 
gen se = . 
gen lb = . 
gen ub = . 

local i = 1 
qui while `i' <= 100 { 
	ci a`i' 
	replace se = r(se) in `i' 
	replace lb = r(lb) in `i'
	replace ub = r(ub) in `i'
	local i = `i' + 1 
} 

l se lb ub 

Note in particular that there is no need 
to read the data in again and again. 

Nick 
[email protected] 

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