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 |
Sofia Ramiro <sofiaramiro@hotmail.com> |

To |
Statalist <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Generate random missing values within a set of variables |

Date |
Sun, 15 Apr 2012 16:41:49 +0100 |

Thank you very much, Maarten! Very useful and I can perfectly run it and adapt to my variables. I have been struggling during the last hours with how to adapt it when I want to generate missings randomly at 2 variables at the same time (and then 3 at the same time), etc. I tried thinking about finding a combination code. For example for the 2 variables missing, if I manage to set the random generation within the numbers 2, 3, 4, 5, 6, 8, 10, 12, 15 and 20, these could identify uniquely every combination (eg: 20 = 4*5, variables 4 and 5 missing). Do you think would be a good approach, or do you propsoe something better? And if this approach, how cna I generate random numbers within these numbers only? Thank you very much! Sofia > Date: Sun, 15 Apr 2012 15:26:32 +0200 > Subject: Re: st: Generate random missing values within a set of variables > From: maartenlbuis@gmail.com > To: statalist@hsphsun2.harvard.edu > > On Sun, Apr 15, 2012 at 2:06 PM, Sofia Ramiro wrote: > > I have 6 variables (without missings) and I would like to randomly generate one missing value in one of the 6 variables per line/observation. I know that with the runiform command we manage to choose observations randomly within one variable (so I could generate random missing values within one variable), but how can I choose randomly one variable out of the 6 to be transformed into missing and make sure that one of them is being transformed per observation? > > *---------- begin example ------------ > // create some data > drop _all > set obs 100 > forvalues i =1/6{ > gen x`i' = rnormal() > } > > // make a variable indicating > // which variable will become missing > gen tomis = ceil(6*runiform()) > > // turn for each observation the > // appropriate variable to missing > forvalues i = 1/6 { > replace x`i' = . if tomis == `i' > } > > // see the result > format x* %6.3g > list in 1/10, clean > *------------- end example ------------- > > 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/ * * 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: Generate random missing values within a set of variables***From:*Eduardo Montoya <ed.montoya@gmail.com>

**References**:**st: Generate random missing values within a set of variables***From:*Sofia Ramiro <sofiaramiro@hotmail.com>

**Re: st: Generate random missing values within a set of variables***From:*Maarten Buis <maartenlbuis@gmail.com>

- Prev by Date:
**Re: st: Generate random missing values within a set of variables** - Next by Date:
**Re: st: Generate random missing values within a set of variables** - Previous by thread:
**Re: st: Generate random missing values within a set of variables** - Next by thread:
**Re: st: Generate random missing values within a set of variables** - Index(es):