replace missings with randomly assigned data

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Torvon
Posts: 34
Joined: Sun Nov 13, 2011 8:41 pm

replace missings with randomly assigned data

Postby Torvon » Wed Mar 14, 2012 3:32 pm

Hey there.

If one had a binary variable 0 and 1, and had missing data.
And now one wanted to replace 75% of the missings with value 0, randomly, and 25% of missings with value 1, randomly, how would one do that in SPSS?

Thanks
Eiko
StatAdvice
Posts: 43
Joined: Sun Mar 11, 2012 2:26 pm

Re: replace missings with randomly assigned data

Postby StatAdvice » Wed Mar 14, 2012 6:41 pm

suppose your variable with some missing values is v1.

Sort the file in such a way that all missing values are on top and "good" values are below missing values.

Then go to Data - Select cases- Random sample - exactly.... from the first "here write the number of missing values in your file". Rename the new filter variable that will be generated by the command(say, v2)

compute v1_1=v1.
if missing(v1)=1 v1_1=v2.
execute.
Now v1_1 is a copy of v1 where everything is done as you wanted.
Eugene
Statistical Consultant
www.StatAdvice.com
info@StatAdvice.com
skype login: StatAdvice
apeape
Posts: 56
Joined: Mon May 02, 2011 6:07 pm

Re: replace missings with randomly assigned data

Postby apeape » Thu Mar 15, 2012 4:26 am

Here is an alternative approach that doesn't require manual noting of the number of missing values or working out the correct values to achieve the 75%/25% split. Replace 'x' with the name of your binary variable.

Code: Select all

if missing(x) y = rv.uniform(0,10).
rank variables=y (a) 
  /percent.
compute nomissing = x.
if (missing(x) and py >75) nomissing = 1.
if (missing(x) and py <76) nomissing = 0.
exe.

delete variables y py.

Who is online

Users browsing this forum: No registered users and 1 guest

cron