Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Replace


From   Daniel Marcelino <[email protected]>
To   [email protected]
Subject   Re: st: Replace
Date   Fri, 2 Sep 2011 20:45:11 -0400

Exactly that Maarten. You have killed my doubt, despite I said the
'wrong' dataset, thanks. I was just looking for an trick to set
missing values with and without constraints to test some stuffs.

Best
Daniel


On Fri, Sep 2, 2011 at 4:52 PM, Maarten Buis <[email protected]> wrote:
> --- 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/
>



-- 
About me: http://danielmarcelino.zip.net/

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index