Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: RE: How to get a list of the names of characters associated with a variable


From   Austin Nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: How to get a list of the names of characters associated with a variable
Date   Thu, 4 Mar 2010 16:20:12 -0500

Clyde Schechter:
Try this example:

prog lookfc
version 8.2
syntax [varlist], t(string)
foreach v of varlist `varlist' {
 loc c: char `v'[]
 loc nall 0
 foreach i of local c {
  loc j: char `v'[`i']
  loc k: subinstr loc j `"`t'"' "", all count(loc n)
  loc nall=`nall'+`n'
  }
 if `nall' > 0 {
  loc var `var' `v'
  }
}
if "`var'"!="" ds `var'
end
sysuse auto, clear
note mpg: inverse of good measure
lookfc, t(meas)

One problem with using index() or strpos() is that they will truncate
strings; according to -help limits-, the maximum length of the
contents of a characteristic is 8,681 characters for Small Stata and
67,784 characters for Stata/IC, Stata/SE, and Stata/MP.

On Thu, Mar 4, 2010 at 3:44 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> Perhaps you mean characteristics. See -help extended_fcn-.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Clyde Schechter MA, MD
>
> I'm trying to write an ado file that will generalize the -lookfor-
> command
> so that it also searches for the target text in characters associated
> with
> variables.  (I need this because I have a data set with a large number
> of
> variables, and the key information is often found not in the label
> [which
> was truncated at 80 characters], but in a character--and the characters
> are not consistently named.)
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index