Statalist


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

RE: AW: st: Programming stata using egen functions


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: AW: st: Programming stata using egen functions
Date   Wed, 29 Apr 2009 12:13:51 +0100

If you want a maximum over a set, it is often easiest to get it using something like this (mix of Stata and pseudocode) 

tempname mymax 
scalar `mymax' = <first value> 

<loop over second ... last values { 
	<new value> = <whatever> 
	scalar `mymax' = max(`mymax', <new value>) 
} 

Nick 
n.j.cox@durham.ac.uk 

Anne Resende

I trying to calculate bounds on E[y(t)].  So I need to calculate the 
lower bound and also a confidence interval on it using boostrap.
So I am trying to calculate:  
                    (1)	                        (2)
SUM    max( E[y|z=s] + max {(E[y|z=s']-E[u|z=u]/(s'-u))*(t-s')}) 
(s>=t)  (s'|s>=s'>=t}    {u|u<t}


(Okumura and Usui, 2006 pag.4).  So here we have s,s’,t and u: every 
letter goes from 8 to 20. I decide to do a program for each, 
t=8,...,20. (So I am trying to calculate the lower bound for each t). I 
also have tried to use all of t together (also create forvalues for t) 
but stata gives a message “No room to add more variables”.  In the 
program that I already sent to you I am considering that t is equal 9, 
so u=8 because u<9  (I do this in line 7 : qui sum `1' if u==8 ). So I 
have tried to use rowmax() to calculate the maximum of the first max 
parenthesis (lines 9 and 11- part (1) + (2)), doesn’t  matter if I 
calculate (2) and take the max or sum (1) and (2) and take the max, as 
I have to take the max again). Then in the reminding lines I have tried 
to multiply  (3) {(1)+(2)}, the whole equation by P(z=s) and then use 
rowtotal to sum all of these observations, as  I have to sum over s>=t. 
(lines 15 and 16 of the programe)

I am afraid that this could be less clear than before but is exactly 
what I trying to do.  Of course that I do not expect you create an ado 
file for me. I just want some tips or some help as you all know much 
more about stata programming. So I really need to move the calculation 
of the maximum outside the loop? 

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