How to perform power analysis using simulation in Stata

I often hear from statistical experts (including on this site) that simulation is the preferred method to calculate power for a clinical trial (rather than using traditional sample size calculation formulae).

I use Stata, and I was wondering if anyone can show me how to do this in detail?

For example, two scenarios:

1) Continuous variable: A new drug given intraoperatively is hypothesized to result in a reduction in the mean troponin release from 2.2 to 1.8 (SD of both 2.0) after cardiac surgery, compared to placebo.

2) Proportions: A sexual educational intervention is hypothesized to result in a reduction in the incidence of HIV transmission amongst teenagers from 20% to 15%.

Assuming a power of 80% and an alpha of 5%, in Stata, I would normally type the following:

1)

sampsi 2.2 1.8, sd(2) power(0.8)

Estimated sample size for two-sample comparison of means

Test Ho: m1 = m2, where m1 is the mean in population 1
and m2 is the mean in population 2
Assumptions:

alpha =   0.0500  (two-sided)
power =   0.8000
m1 =      2.2
m2 =      1.8
sd1 =        2
sd2 =        2
n2/n1 =     1.00

Estimated required sample sizes:
n1 =      393
n2 =      393


and for 2) I would type:

 sampsi 0.2 0.15, power(0.8)

Estimated sample size for two-sample comparison of proportions

Test Ho: p1 = p2, where p1 is the proportion in population 1
and p2 is the proportion in population 2
Assumptions:

alpha =   0.0500  (two-sided)
power =   0.8000
p1 =   0.2000
p2 =   0.1500
n2/n1 =   1.00

Estimated required sample sizes:

n1 =      945
n2 =      945


Can anyone please show me how the simulation technique might look in Stata for these two examples?

Many thanks!

-
If you are comparing the means between two groups, simulation would just add noise to the existing formula used by sampsi or any other analytic power calculation tools. Simulation is only called for if you have a complicated analysis, say survival curves of different shapes and an observational component that requires propensity score matching. There is no freaking way to get any idea of the power for such a design analytically, so you have to simulate with different sample sizes until you hit your 5%/80% magic combination. –  StasK Sep 6 '11 at 18:01