In my last three posts, I showed you how to calculate power for a *t* test using Monte Carlo simulations, how to integrate your simulations into Stata’s **power** command, and how to do this for linear and logistic regression models. In today’s post, I’m going to show you how to estimate power for multilevel/longitudinal models using simulations. You may want to review my earlier post titled “How to simulate multilevel/longitudinal data” before you read this post. Read more…

In my last two posts, I showed you how to calculate power for a *t* test using Monte Carlo simulations and how to integrate your simulations into Stata’s **power** command. In today’s post, I’m going to show you how to do these tasks for linear and logistic regression models. The strategy and overall structure of the programs for linear and logistic regression are similar to the *t* test examples. The parts that will change are the simulation of the data and the models used to test the null hypothesis. Read more…

In my last post, I showed you how to calculate power for a *t* test using Monte Carlo simulations. In this post, I will show you how to integrate your simulations into Stata’s **power** command so that you can easily create custom tables and graphs for a range of parameter values. Read more…

Power and sample-size calculations are an important part of planning a scientific study. You can use Stata’s **power** commands to calculate power and sample-size requirements for dozens of commonly used statistical tests. But there are no simple formulas for more complex models such as multilevel/longitudinal models and structural equation models (SEMs). Monte Carlo simulations are one way to calculate power and sample-size requirements for complex models, and Stata provides all the tools you need to do this. You can even integrate your simulations into Stata’s **power** commands so that you can easily create custom tables and graphs for a range of parameter values. Read more…

**Overview**

I describe how to generate random numbers and discuss some features added in Stata 14. In particular, Stata 14 includes a new default random-number generator (RNG) called the Mersenne Twister (Matsumoto and Nishimura 1998), a new function that generates random integers, the ability to generate random numbers from an interval, and several new functions that generate random variates from nonuniform distributions.

**Random numbers from the uniform distribution**

In the example below, we use **runiform()** to create Read more…

For those interested in **how pseudo random number generators work**, I just wrote something on Statalist which you can see in the Statalist archives by clicking the link even if you do not subscribe:

**http://www.stata.com/statalist/archive/2012-10/msg01129.html**

To remind you, I’ve been writing about how to *use* random-number generators in parts **1**, **2**, and **3**, and I still have one more posting I want to write on the subject. What I just wrote on Statalist, however, is about how random-number generators work, and I think you will find it interesting.

To find out more about Statalist, see

**Statalist**

**How to successfully ask a question on Statalist**

The topic for today is drawing random samples with replacement. If you haven’t read part 1 and part 2 of this series on random numbers, do so. In the series we’ve discussed that Read more…

Last time I told you that Stata’s **runiform()** function generates rectangularly (uniformly) distributed random numbers over [0, 1), from 0 to nearly 1, and to be precise, over [0, 0.999999999767169356]. And I gave you two formulas,

- To generate
*continuous* random numbers between *a* and *b*, use
**generate double u =** **(***b***–***a***)*runiform() +** *a*

The random numbers will not actually be between *a* and *b*: they will be between *a* and nearly *b*, but the top will be so close to *b*, namely 0.999999999767169356**b*, that it will not matter.

- To generate
*integer* random numbers between *a* and *b*, use Read more…

I want to start a series on using Stata’s random-number function. Stata in fact has ten random-number functions: Read more…