Quantcast

Replace missing values by 0

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Replace missing values by 0

Hobst
I have two variabled called "prean" and "pa_kum" that contain missing values. These missing values i would like to replace by 0 (zero). What command can i use to do this?

Thanks in advance for your support. Regards
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: Replace missing values by 0

Martin Weiss-5

<>



*************
clear*
input myvar
1
3
5
.
3
6
7
end

recode myvar (mis = 0)
l
*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Hobst
Gesendet: Montag, 9. August 2010 10:55
An: [hidden email]
Betreff: st: Replace missing values by 0

I have two variabled called "prean" and "pa_kum" that contain missing
values.
These missing values i would like to replace by 0 (zero). What command can i
use to do this?

Thanks in advance for your support. Regards
--
View this message in context:
http://statalist.1588530.n2.nabble.com/Replace-missing-values-by-0-tp5388239
p5388239.html
Sent from the Statalist mailing list archive at Nabble.com.
*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Replace missing values by 0

Tirthankar Chakravarty
In reply to this post by Hobst
-mvencode-

T

2010/8/9 Hobst <[hidden email]>:

> I have two variabled called "prean" and "pa_kum" that contain missing values.
> These missing values i would like to replace by 0 (zero). What command can i
> use to do this?
>
> Thanks in advance for your support. Regards
> --
> View this message in context: http://statalist.1588530.n2.nabble.com/Replace-missing-values-by-0-tp5388239p5388239.html
> Sent from the Statalist mailing list archive at Nabble.com.
> *
> *   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/
>



--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).

*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Replace missing values by 0

nshephard
Administrator
In reply to this post by Hobst
On Mon, Aug 9, 2010 at 8:55 AM, Hobst <[hidden email]> wrote:
> I have two variabled called "prean" and "pa_kum" that contain missing values.
> These missing values i would like to replace by 0 (zero). What command can i
> use to do this?

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}

...is one way to skin this cat.

> Thanks in advance for your support. Regards

This is a very basic question though.  You may well benefit from
reading the Users Guide and/or  taking the Stata Net Course 101 :
Introduction to Stata (see http://www.stata.com/netcourse/nc101.html).

Neil

--
"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell

Email - [hidden email]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: st: Replace missing values by 0

Martin Weiss-5

<>

Stata even forgives the missing blank after -if-! Amazing!

*************
clear*
inp prean pa_kurn
2 3
. 5
. 3
. .
4 5
end
foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}
l
*************


One problem with this "first-principles" approach is that you have to
compare explicitly with all missing values, i.e. also the extended ones.
-recode- can help avoid this problem.



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Neil Shephard
Gesendet: Montag, 9. August 2010 11:01
An: [hidden email]
Betreff: Re: st: Replace missing values by 0

On Mon, Aug 9, 2010 at 8:55 AM, Hobst <[hidden email]> wrote:
> I have two variabled called "prean" and "pa_kum" that contain missing
values.
> These missing values i would like to replace by 0 (zero). What command can
i
> use to do this?

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}

...is one way to skin this cat.

> Thanks in advance for your support. Regards

This is a very basic question though.  You may well benefit from
reading the Users Guide and/or  taking the Stata Net Course 101 :
Introduction to Stata (see http://www.stata.com/netcourse/nc101.html).

Neil

--
"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell

Email - [hidden email]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Replace missing values by 0

Nick Cox
In reply to this post by Tirthankar Chakravarty
I have one specific and one general comment here.

Specifically, Martin is correct to underline that . is not the only missing value, but the loop in question is easily fixed by

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if missing(x)
}

Generally, a minimal -search missing- points to several resources. One of the very first entries, to [I] missing values, answers this question comprehensively, so it is difficult to see why it was felt necessary to send it to Statalist.

Nick
[hidden email]

Martin Weiss
============

Stata even forgives the missing blank after -if-! Amazing!

*************
clear*
inp prean pa_kurn
2 3
. 5
. 3
. .
4 5
end
foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}
l
*************


One problem with this "first-principles" approach is that you have to compare explicitly with all missing values, i.e. also the extended ones.
-recode- can help avoid this problem.

Neil Shephard
=============

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}

...is one way to skin this cat.



Martin Weiss
============

clear*
input myvar
1
3
5
.
3
6
7
end

recode myvar (mis = 0)
l


Tirthankar Chakravarty

-mvencode-

Tobias Friedli

> I have two variabled called "prean" and "pa_kum" that contain missing values.
> These missing values i would like to replace by 0 (zero). What command can i
> use to do this?

*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Replace missing values by 0

Nick Cox
Should be

replace `x' = 0 if missing(`x')

Nick
[hidden email]

-----Original Message-----
From: Nick Cox

I have one specific and one general comment here.

Specifically, Martin is correct to underline that . is not the only missing value, but the loop in question is easily fixed by

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if missing(x)
}

Generally, a minimal -search missing- points to several resources. One of the very first entries, to [I] missing values, answers this question comprehensively, so it is difficult to see why it was felt necessary to send it to Statalist.

Nick
[hidden email]

Martin Weiss
============

Stata even forgives the missing blank after -if-! Amazing!

*************
clear*
inp prean pa_kurn
2 3
. 5
. 3
. .
4 5
end
foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}
l
*************


One problem with this "first-principles" approach is that you have to compare explicitly with all missing values, i.e. also the extended ones.
-recode- can help avoid this problem.

Neil Shephard
=============

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}

...is one way to skin this cat.



Martin Weiss
============

clear*
input myvar
1
3
5
.
3
6
7
end

recode myvar (mis = 0)
l


Tirthankar Chakravarty

-mvencode-

Tobias Friedli

> I have two variabled called "prean" and "pa_kum" that contain missing values.
> These missing values i would like to replace by 0 (zero). What command can i
> use to do this?

*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: st: Replace missing values by 0

Martin Weiss-5

<>



*************
replace `x' = 0 if (`x' >= .)
*************

might also do the trick.

It is important, in all solutions offered in this thread, to make sure you feed them only numeric variables. Nick`s -mi()- function does cover strings as well, but the first part of the -replace- command is then no longer correct.



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Nick Cox
Gesendet: Montag, 9. August 2010 17:20
An: [hidden email]
Betreff: RE: st: Replace missing values by 0

Should be

replace `x' = 0 if missing(`x')

Nick
[hidden email]

-----Original Message-----
From: Nick Cox

I have one specific and one general comment here.

Specifically, Martin is correct to underline that . is not the only missing value, but the loop in question is easily fixed by

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if missing(x)
}

Generally, a minimal -search missing- points to several resources. One of the very first entries, to [I] missing values, answers this question comprehensively, so it is difficult to see why it was felt necessary to send it to Statalist.

Nick
[hidden email]

Martin Weiss
============

Stata even forgives the missing blank after -if-! Amazing!

*************
clear*
inp prean pa_kurn
2 3
. 5
. 3
. .
4 5
end
foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}
l
*************


One problem with this "first-principles" approach is that you have to compare explicitly with all missing values, i.e. also the extended ones.
-recode- can help avoid this problem.

Neil Shephard
=============

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
}

...is one way to skin this cat.



Martin Weiss
============

clear*
input myvar
1
3
5
.
3
6
7
end

recode myvar (mis = 0)
l


Tirthankar Chakravarty

-mvencode-

Tobias Friedli

> I have two variabled called "prean" and "pa_kum" that contain missing values.
> These missing values i would like to replace by 0 (zero). What command can i
> use to do this?

*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Replace missing values by 0

Lachenbruch, Peter
In reply to this post by Hobst
In all of the discussion of this query, nobody has asked why it is important to do this?  If you are computing means, the 0 values will distort the mean (or median if enough), and if you simply want to ignore zeros with "if x~=0") retaining the missing value will do this automatically.  

I am unsure if I've ever had a reason to convert missing values to a numeric value, but have had many times when the -9 for missing (or whatever) had to be set to "."

Tony

Peter A. Lachenbruch
Department of Public Health
Oregon State University
Corvallis, OR 97330
Phone: 541-737-3832
FAX: 541-737-4001


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Hobst
Sent: Monday, August 09, 2010 1:55 AM
To: [hidden email]
Subject: st: Replace missing values by 0

I have two variabled called "prean" and "pa_kum" that contain missing values.
These missing values i would like to replace by 0 (zero). What command can i
use to do this?

Thanks in advance for your support. Regards
--
View this message in context: http://statalist.1588530.n2.nabble.com/Replace-missing-values-by-0-tp5388239p5388239.html
Sent from the Statalist mailing list archive at Nabble.com.
*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: RE: Replace missing values by 0

David Radwin-2
Tony,

Sometimes data, especially count data, are stored in a spreadsheet where a
blank cell indicates a zero value. For example, if the data are
hand-entered and there are a lot of zero values, it is more efficient not
to enter a zero, and many spreadsheet functions treat the blank cell as a
zero value.

However, if you paste or -insheet- these data into Stata, the blank cells
are encoded as missing values. In this case it is necessary to convert the
missing values to zeroes.

David

--
David Radwin
Research Associate
MPR Associates, Inc.
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-849-4942
Fax: 510-849-0794

www.mprinc.com


> -----Original Message-----
> From: [hidden email] [mailto:owner-
> [hidden email]] On Behalf Of Lachenbruch, Peter
> Sent: Monday, August 09, 2010 2:59 PM
> To: '[hidden email]'
> Subject: st: RE: Replace missing values by 0
>
> In all of the discussion of this query, nobody has asked why it is
> important to do this?  If you are computing means, the 0 values will
> distort the mean (or median if enough), and if you simply want to ignore
> zeros with "if x~=0") retaining the missing value will do this
> automatically.
>
> I am unsure if I've ever had a reason to convert missing values to a
> numeric value, but have had many times when the -9 for missing (or
> whatever) had to be set to "."
>
> Tony
>
> Peter A. Lachenbruch
> Department of Public Health
> Oregon State University
> Corvallis, OR 97330
> Phone: 541-737-3832
> FAX: 541-737-4001
>
>
> -----Original Message-----
> From: [hidden email] [mailto:owner-
> [hidden email]] On Behalf Of Hobst
> Sent: Monday, August 09, 2010 1:55 AM
> To: [hidden email]
> Subject: st: Replace missing values by 0
>
> I have two variabled called "prean" and "pa_kum" that contain missing
> values.
> These missing values i would like to replace by 0 (zero). What command
can
> i
> use to do this?
>
> Thanks in advance for your support. Regards
> --
> View this message in context:
> http://statalist.1588530.n2.nabble.com/Replace-missing-values-by-0-
> tp5388239p5388239.html
> Sent from the Statalist mailing list archive at Nabble.com.

*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: RE: RE: Replace missing values by 0

Lachenbruch, Peter
But the original question was about missing values being represented as 0.  
Use of a blank cell for 0 allows the confusion of missing and true 0.  At any rate, if you want to code missing as 0 that's a problem to my mind.

Tony

Peter A. Lachenbruch
Department of Public Health
Oregon State University
Corvallis, OR 97330
Phone: 541-737-3832
FAX: 541-737-4001


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of David Radwin
Sent: Monday, August 09, 2010 3:29 PM
To: [hidden email]
Subject: st: RE: RE: Replace missing values by 0

Tony,

Sometimes data, especially count data, are stored in a spreadsheet where a
blank cell indicates a zero value. For example, if the data are
hand-entered and there are a lot of zero values, it is more efficient not
to enter a zero, and many spreadsheet functions treat the blank cell as a
zero value.

However, if you paste or -insheet- these data into Stata, the blank cells
are encoded as missing values. In this case it is necessary to convert the
missing values to zeroes.

David

--
David Radwin
Research Associate
MPR Associates, Inc.
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-849-4942
Fax: 510-849-0794

www.mprinc.com


> -----Original Message-----
> From: [hidden email] [mailto:owner-
> [hidden email]] On Behalf Of Lachenbruch, Peter
> Sent: Monday, August 09, 2010 2:59 PM
> To: '[hidden email]'
> Subject: st: RE: Replace missing values by 0
>
> In all of the discussion of this query, nobody has asked why it is
> important to do this?  If you are computing means, the 0 values will
> distort the mean (or median if enough), and if you simply want to ignore
> zeros with "if x~=0") retaining the missing value will do this
> automatically.
>
> I am unsure if I've ever had a reason to convert missing values to a
> numeric value, but have had many times when the -9 for missing (or
> whatever) had to be set to "."
>
> Tony
>
> Peter A. Lachenbruch
> Department of Public Health
> Oregon State University
> Corvallis, OR 97330
> Phone: 541-737-3832
> FAX: 541-737-4001
>
>
> -----Original Message-----
> From: [hidden email] [mailto:owner-
> [hidden email]] On Behalf Of Hobst
> Sent: Monday, August 09, 2010 1:55 AM
> To: [hidden email]
> Subject: st: Replace missing values by 0
>
> I have two variabled called "prean" and "pa_kum" that contain missing
> values.
> These missing values i would like to replace by 0 (zero). What command
can
> i
> use to do this?
>
> Thanks in advance for your support. Regards
> --
> View this message in context:
> http://statalist.1588530.n2.nabble.com/Replace-missing-values-by-0-
> tp5388239p5388239.html
> Sent from the Statalist mailing list archive at Nabble.com.

*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: RE: Replace missing values by 0

David Bell-3
In reply to this post by David Radwin-2
-
In many cases, skip patterns in questionnaires leave behind missing values, either -9's or .'s.  If you told the interviewer that you didn't do behavior X in the past year, you won't be asked how many times you did X in the past 30 days.  The missing value for 30-day behavior X really does represent a zero.

Dave
====================================
David C. Bell
Professor of Sociology
Indiana University Purdue University Indianapolis (IUPUI)
(317) 278-1336
====================================




On Aug 9, 2010, at 6:29 PM, David Radwin wrote:

> Tony,
>
> Sometimes data, especially count data, are stored in a spreadsheet where a
> blank cell indicates a zero value. For example, if the data are
> hand-entered and there are a lot of zero values, it is more efficient not
> to enter a zero, and many spreadsheet functions treat the blank cell as a
> zero value.
>
> However, if you paste or -insheet- these data into Stata, the blank cells
> are encoded as missing values. In this case it is necessary to convert the
> missing values to zeroes.
>
> David
>
> --
> David Radwin
> Research Associate
> MPR Associates, Inc.
> 2150 Shattuck Ave., Suite 800
> Berkeley, CA 94704
> Phone: 510-849-4942
> Fax: 510-849-0794
>
> www.mprinc.com
>
>
>> -----Original Message-----
>> From: [hidden email] [mailto:owner-
>> [hidden email]] On Behalf Of Lachenbruch, Peter
>> Sent: Monday, August 09, 2010 2:59 PM
>> To: '[hidden email]'
>> Subject: st: RE: Replace missing values by 0
>>
>> In all of the discussion of this query, nobody has asked why it is
>> important to do this?  If you are computing means, the 0 values will
>> distort the mean (or median if enough), and if you simply want to ignore
>> zeros with "if x~=0") retaining the missing value will do this
>> automatically.
>>
>> I am unsure if I've ever had a reason to convert missing values to a
>> numeric value, but have had many times when the -9 for missing (or
>> whatever) had to be set to "."
>>
>> Tony
>>
>> Peter A. Lachenbruch
>> Department of Public Health
>> Oregon State University
>> Corvallis, OR 97330
>> Phone: 541-737-3832
>> FAX: 541-737-4001
>>
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:owner-
>> [hidden email]] On Behalf Of Hobst
>> Sent: Monday, August 09, 2010 1:55 AM
>> To: [hidden email]
>> Subject: st: Replace missing values by 0
>>
>> I have two variabled called "prean" and "pa_kum" that contain missing
>> values.
>> These missing values i would like to replace by 0 (zero). What command
> can
>> i
>> use to do this?
>>
>> Thanks in advance for your support. Regards
>> --
>> View this message in context:
>> http://statalist.1588530.n2.nabble.com/Replace-missing-values-by-0-
>> tp5388239p5388239.html
>> Sent from the Statalist mailing list archive at Nabble.com.
>
> *
> *   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: RE: Replace missing values by 0

Richard Goldstein
be careful -- while what you say is true, you also won't be asked if
you were happy doing "x" -- and 0 is not correct for that

I definitely agree with Tony that just mindlessly doing what the OP
asked is very dangerous

Rich

On 8/10/10 12:13 PM, David Bell wrote:

> -
> In many cases, skip patterns in questionnaires leave behind missing values, either -9's or .'s.  If you told the interviewer that you didn't do behavior X in the past year, you won't be asked how many times you did X in the past 30 days.  The missing value for 30-day behavior X really does represent a zero.
>
> Dave
> ====================================
> David C. Bell
> Professor of Sociology
> Indiana University Purdue University Indianapolis (IUPUI)
> (317) 278-1336
> ====================================
>
>
>
>
> On Aug 9, 2010, at 6:29 PM, David Radwin wrote:
>
>> Tony,
>>
>> Sometimes data, especially count data, are stored in a spreadsheet where a
>> blank cell indicates a zero value. For example, if the data are
>> hand-entered and there are a lot of zero values, it is more efficient not
>> to enter a zero, and many spreadsheet functions treat the blank cell as a
>> zero value.
>>
>> However, if you paste or -insheet- these data into Stata, the blank cells
>> are encoded as missing values. In this case it is necessary to convert the
>> missing values to zeroes.
>>
>> David
>>
>> --
>> David Radwin
>> Research Associate
>> MPR Associates, Inc.
>> 2150 Shattuck Ave., Suite 800
>> Berkeley, CA 94704
>> Phone: 510-849-4942
>> Fax: 510-849-0794
>>
>> www.mprinc.com
>>
>>
>>> -----Original Message-----
>>> From: [hidden email] [mailto:owner-
>>> [hidden email]] On Behalf Of Lachenbruch, Peter
>>> Sent: Monday, August 09, 2010 2:59 PM
>>> To: '[hidden email]'
>>> Subject: st: RE: Replace missing values by 0
>>>
>>> In all of the discussion of this query, nobody has asked why it is
>>> important to do this?  If you are computing means, the 0 values will
>>> distort the mean (or median if enough), and if you simply want to ignore
>>> zeros with "if x~=0") retaining the missing value will do this
>>> automatically.
>>>
>>> I am unsure if I've ever had a reason to convert missing values to a
>>> numeric value, but have had many times when the -9 for missing (or
>>> whatever) had to be set to "."
>>>
>>> Tony
>>>
>>> Peter A. Lachenbruch
>>> Department of Public Health
>>> Oregon State University
>>> Corvallis, OR 97330
>>> Phone: 541-737-3832
>>> FAX: 541-737-4001
>>>
>>>
>>> -----Original Message-----
>>> From: [hidden email] [mailto:owner-
>>> [hidden email]] On Behalf Of Hobst
>>> Sent: Monday, August 09, 2010 1:55 AM
>>> To: [hidden email]
>>> Subject: st: Replace missing values by 0
>>>
>>> I have two variabled called "prean" and "pa_kum" that contain missing
>>> values.
>>> These missing values i would like to replace by 0 (zero). What command
>> can
>>> i
>>> use to do this?
>>>
>>> Thanks in advance for your support. Regards
>>> --
>>> View this message in context:
>>> http://statalist.1588530.n2.nabble.com/Replace-missing-values-by-0-
>>> tp5388239p5388239.html
>>> Sent from the Statalist mailing list archive at Nabble.com.
*
*   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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: RE: RE: RE: Replace missing values by 0

Nick Cox
In reply to this post by Lachenbruch, Peter
I'd put it this way.

If blanks that should be zeros are interpreted by Stata on input as
missings, then it's appropriate to map those missings to zeros before
analysis.

It's easy enough to show that this can happen, e.g. by copy and paste
from a spreadsheet to Stata's data editor.

Clearly, anyone doing this should be certain that it is exactly what
they want. If there are other genuine missings, replacing them by zero
is a very bad idea.

Nick
[hidden email]

Lachenbruch, Peter

But the original question was about missing values being represented as
0.  
Use of a blank cell for 0 allows the confusion of missing and true 0.
At any rate, if you want to code missing as 0 that's a problem to my
mind.


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