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   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: Setting a missing value in a generic context
Date   Mon, 07 Mar 2005 09:02:48 -0500

Thanks to Morten for that suggestion.

It is useful, in that it takes the required code and packages it into a program (and can eliminate repeated coding), but I was hoping that there might be something built-in that does it. On the other hand, any solution, whether programmed or built-in, would need to do such a test of the type anyway. So a built-in, if it existed, might not be much better.

If you are interested, I have used similar code in a slightly different way, which enables either -replace- or -post- (or both):

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

replace `v' = `missvalue'


postfile postname `typ' var1 ...
post postname (`missvalue') ...

-- David

At 06:32 PM 3/5/2005 +0100, you wrote:

Hi David,

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

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'

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



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.

What I'd like is something like
  replace `v' = universal_missing_symbol_that_works_regardless_of_data_type
David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
*   For searches and help try:

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