SHAZAM Community
Ask Your Question
0

Fixing missing values

asked 2014-12-10 09:08:11 +0000

Tolu gravatar image

updated 2014-12-10 19:53:23 +0000

What is the best way to replace all missing values with the means of the variables in a large dataset? I don't want to use SHAZAM's default -99999 because it affects my estimation. I would like to use all my observations so I don't want to use the SKIPMISS command.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-12-10 19:52:47 +0000

Here is an example:

* Read some data.
sample 1 5
read var1 var2 var3  
1           2        3
1      -99999        3
1           2   -99999  
-99999      2        3
1           2        3

* Calculate means for the 4 observations and print them.
set skipmiss
stat var1 var2 var3 / mean=means
print means

* Set missing value to means for any variables we want.
set noskipmiss
if(var1.eq.-99999) var1=means:1
if(var2.eq.-99999) var2=means:2
if(var3.eq.-99999) var3=means:3

* Check the result. 5 Observations shown with means correct.
stat var1 var2 var3

The output is:

 Welcome to SHAZAM (Double Precision) v11.1 -  OCT 2014 WIN-NT   PAR=112400
 ...NOTE..CURRENT WORKING DIRECTORY IS: C:\Users\David.SOFTWAREONE\Documents\SHAZAM\Miss

 |_* Read some data.
 |_sample 1 5
 |_read var1 var2 var3
 ...NOTE..    3 VARIABLES AND        5 OBSERVATIONS STARTING AT OBS       1

 |_* Calculate means for the 4 observations and print them.
 |_set skipmiss

 |_stat var1 var2 var3 / mean=means
 NAME        N    MEAN        ST. DEV      VARIANCE     MINIMUM      MAXIMUM
 VAR1          4   1.0000     0.00000E+00 0.00000E+00   1.0000       1.0000
 VAR2          4   2.0000     0.00000E+00 0.00000E+00   2.0000       2.0000
 VAR3          4   3.0000     0.00000E+00 0.00000E+00   3.0000       3.0000

 |_print means
 MEANS
    1.000000       2.000000       3.000000

 |_* Set missing value to means for any variables we want.
 |_set noskipmiss
 |_if(var1.eq.-99999) var1=means:1
 |_if(var2.eq.-99999) var2=means:2
 |_if(var3.eq.-99999) var3=means:3

 |_* Check the result. 5 Observations shown with means correct.
 |_stat var1 var2 var3
 NAME        N    MEAN        ST. DEV      VARIANCE     MINIMUM      MAXIMUM
 VAR1          5   1.0000     0.00000E+00 0.00000E+00   1.0000       1.0000
 VAR2          5   2.0000     0.00000E+00 0.00000E+00   2.0000       2.0000
 VAR3          5   3.0000     0.00000E+00 0.00000E+00   3.0000       3.0000
edit flag offensive delete link more
0

answered 2014-12-11 01:14:25 +0000

Tolu gravatar image

Thanks SHAZAM help. Now, this is the definition of user support.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-12-10 09:08:11 +0000

Seen: 165 times

Last updated: Dec 11 '14