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

R: st: a possible - foreach - question?

From   "Carlo Lazzaro" <>
To   <>
Subject   R: st: a possible - foreach - question?
Date   Tue, 14 Oct 2008 17:18:06 +0200

Dear Austin,
many thanks for your helpful hints. I have just modified your syntax (too
advanced for me) in order to approach my ultimate goal, that is calculating,
for each one of the 10,000 iterations, how many times ICER_round*Delta_Q was
> Delta_C (please, see below). I was not absolutely clear on this point in
my previous messages as it was a subsequent thought of mine.
Once again I would like to express my grateful thankfulness  to Austin, Ben,
Johannes, and Martin (in alphabetical order) for their support and for
having increased my poor skills about Stata programming. This experience
makes me think that the famous Bayesian saying "today's posterior will be
tomorrow's prior" applies very well when it comes to knowledge improvement
that can be obtained from more experienced Statalisters.

Thanks a lot again and Kind Regards,

g double d=.
(10000 missing values generated)

. edit
- preserve

. qui forv i=1/`=_N' {
.  if  ICER[`i']<. {
. g double tmp=  ICER_round[`i']* Delta_Q> Delta_C
.   su tmp, meanonly
. replace d=r(mean) in `i'
.   drop tmp
.   }
.   }
-----Messaggio originale-----
[] Per conto di Austin Nichols
Inviato: martedì 14 ottobre 2008 15.31
Oggetto: Re: st: a possible - foreach - question?

Carlo Lazzaro <>
Not sure I've understood, but if so, here is one method of calculation.

use bp* tcresult using, clear
ren bpsystol a
ren bpdiast b
ren tcresult c
g double d=.
qui forv i=1/`=_N' {
 if a[`i']<. {
  g double tmp=a[`i']*b-c
  su tmp, meanonly
  replace d=r(mean) in `i'
  drop tmp

On Tue, Oct 14, 2008 at 4:50 AM, Carlo Lazzaro
<> wrote:
> Dear Statalisters,
> I have three variables (a; b; C with 10,000 observations each) in long
> format.
> For each value of a I would like to obtain the following one:
> (a1 * b1) - c1
> .
> .
> .
> .
> (a1*b10,000)-c10,000;
> Repeat the above reported would-be 10,000 times (i.e., from a1 to a10,000)
> Create a new variable d in which the mean of each one of the 10,000
> iterations are stored and can be displayed.
> I suppose there's way of doing this with Stata 9.2/SE, but I cannot figure
> out the proper syntax.
*   For searches and help try:

*   For searches and help try:

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