Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Maarten Buis <maartenlbuis@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Replace |

Date |
Fri, 2 Sep 2011 22:52:54 +0200 |

--- on Fri, Sep 2, 2011 at 10:29 PM, Daniel Marcelino wrote: > I'm in doubt how I could run a loop to randomly introduce 100 missing > values in the 'auto' dataset. That is easy as the auto dataset contains only 74 observations ;) Lets assume that you wanted exactly 20 missing observations on the variable mpg sysuse auto, clear gen s = runiform() sort s replace mpg = . in 1/20 Generally I like to specify a probability of getting a missing rather than a fixed number of missings. Below I assume you want a 20% chance of getting a missing. sysuse auto, clear replace mpg = . if runiform() < .2 Generalizations of this trick that will allow you let that probability depend on other variables (e.g. to check how important the MAR, MCAR and NMAR assumptions are) can be found in: M.L. Buis (2007b), "Stata tip 48: Discrete uses for uniform()", The Stata Journal, 7(3), pp. 434-435. <http://www.stata-journal.com/article.html?article=pr0032> Hope this helps, Maarten -------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- * * 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/

**Follow-Ups**:**Re: st: Replace***From:*Daniel Marcelino <dmsilv@gmail.com>

**References**:**st: Replace***From:*Daniel Marcelino <dmsilv@gmail.com>

- Prev by Date:
**Re: Re: st: Polynomial Fitting and RD Design** - Next by Date:
**Re: st: Asking: choose between collapse and sort,copy-paste** - Previous by thread:
**st: Replace** - Next by thread:
**Re: st: Replace** - Index(es):