Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: "dirty trick": metadata in extended missing value labels


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: "dirty trick": metadata in extended missing value labels
Date   Mon, 16 Nov 2009 11:29:37 -0500



[email protected] wrote:
Hi Statalisters,

the following is a "dirty" but - at least for me - useful trick:



Several have suggested using characteristics to store this kind of
info, and I concur. The main disadvantage of both schemes
is that it can be difficult to figure out which variables have
which characteristics - I wrote the program below to list variables
that either have a certain characteristic defined, or have a
certain value for a given characteristic. Ie,

 dchar, char(graph percent)

will list all variables with characteristic 'graph' defined
and equal to 'percent'; or

 dchar, char(graph)

will simply list all variables with characteristics `graph'
defined. The program also takes a varlist, to limit the search,
and stores the hit list in r(varlist).

hth,
Jeph



*****************************************
*   DCHAR
*   program to get list of variables with
*   certain characteristics
*!
*!  version 1.0       27 Aug 2009
*****************************************

program define dchar, rclass
        syntax [varlist] , CHar(string)
        local char1 : word 1 of `char'
        local char2 : word 2 of `char'
        local rlist ""
        local numvars 0
        di ""
        foreach V of varlist `varlist' {
                local charlist : char `V'[]
                local found : list char1 in charlist
                if `found'>0 {
                        if "`char2'"!="" {
                                local charval : char `V'[`char1']
                                if "`charval'"=="`char2'" {
                                        di in y "`V'" _col(40) in g ///
				          "`char1'"  _col(50) "`char2'"
                                        local rlist "`rlist'`V' "
                                        local numvars = `numvars'+1
                                }
                        }
                        else {
                                local charval : char `V'[`char1']
                                di in y "`V'" _col(40) in g ///
				   "`char1'" _col(50) "`charval'"
                                local rlist "`rlist'`V' "
                                local numvars = `numvars'+1
                        }
                }
        }
        return local varlist "`rlist'"
        return scalar numvars= `numvars'
end
*****************************************
*
*   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/



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