Statalist


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

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


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: "dirty trick": metadata in extended missing value labels
Date   Tue, 17 Nov 2009 11:18:21 -0000

We agree. 

Nick 
[email protected] 

Jeph Herrin

Yes, originally I wrote this as a wrapper for -ds-, but found I
still had to loop over the return list to check for assigned values
so bagged -ds- altogether in the end.

That said, obviously, if you don't care what the value of a
characteristic is, there is no reason to assign such values.
I have datasets that consist of dozens of linked tables containing
thousands of variables. The more information I can attach to a
variable the first time I look at it, the more I can automate
my analyses and output, which in such a situation is highly
desirable.

Nick Cox wrote:

> Note that the official Stata command -ds- already has options -has()-
> and -not()- that permit identification of variables with or without
> named characteristics (but not their contents, as here). 
> 
> There is much scope for different programming styles, but flagging
that
> a variable has a particular property can be done by assigning any
> non-empty text. Putting informative detail _inside_ characteristics
has
> disadvantages as well as advantages, as the programmer is
> correspondingly obliged to, or able to, look inside. 

Jeph Herrin
 
> [email protected] wrote:

>> 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