Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Setting a missing value in a generic context


From   Morten Andersen <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Setting a missing value in a generic context
Date   Sat, 05 Mar 2005 18:32:06 +0100

Hi David,

You actually provided the solution yourself. Just wrap it up into
repmiss.ado:

program repmiss
    version 8
    syntax varname [if] [in]
    local typ: type `varlist'
    if substr("`typ'", 1, 3) == "str" {
      replace `varlist' = "" `if' `in'
    }
    else {
      replace `varlist' = . `if' `in'
    }
end

However, when using post you can't get around knowing the variable types, I
believe.

Regards,

Morten

----------------------------------------------------------------------------
Morten Andersen, MD, PhD               Research Unit for General Practice
Senior Researcher                      University of Southern Denmark
Phone   +45 6550 3791                  J.B. Winsloews Vej 9
Fax     +45 6311 1642                  DK-5000 Odense C
E-mail  [email protected]        Denmark
----------------------------------------------------------------------------

Hi everyone,

Is there a concise way to set a variable to a missing value if you don't
know its type (string vs. numeric)?  This would be the reverse of the mi()
function -- reverse in that you are setting rather than testing the value.

Suppose I have a local v that contains a variable name, and I want to
replace the variable to missing.

Is there a way to do it in one easy command?  Presently, I have been doing
something like...

local typ: type `v'
if substr("`typ'", 1, 3) == "str" {
  replace `v' = ""
}
else {
  replace `v' = .
}

(or other similar things involving macros).  (And in another setting, I am
-post-ing a missing value, rather than replacing it in a variable.)

What I'd like is something like
  replace `v' = universal_missing_symbol_that_works_regardless_of_data_type

I don't suppose it exists, but please let me know if I've overlooked
something.
If it doesn't exist, it's on my wish list.

-- David

David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index