Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[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
Eric Booth <[email protected]>
To
[email protected]
Subject
Re: st: RE: How to get a list of the names of characters associated with a variable
Date
Thu, 4 Mar 2010 15:54:51 -0600
>
Nevermind--I didn't read the helpfile carefully enough. It says " has(char problem) selects all variables with a characteristic named problem."
So, I have to specify the name of the char with -ds-
**
sysuse auto, clear
note mpg: inverse of good measure
char mpg[one] test
ds, has(char one)
di "`r(varlist)'"
**
~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Mar 4, 2010, at 3:49 PM, Eric Booth wrote:
>>
>
> When I saw Austin's solution for searching the char of the variables, my first thought was that -ds- should be able to do that--but I couldn't get it to work with -ds-. I'm not sure what I'm doing wrong here :
>
> **
> sysuse auto, clear
> note mpg: inverse of good measure
>
> ds, has(char *meas*)
> di "`r(varlist)'"
> ds, has(char *m*)
> di "`r(varlist)'"
> ds, has(note "inverse of good measure")
> di "`r(varlist)'"
>
> **
>
> Also, Austin's note on using index() is an important warning for the example I posted as well.
>
> ~ Eric
>
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
> Office: +979.845.6754
>
> On Mar 4, 2010, at 3:20 PM, Austin Nichols wrote:
>
>> 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 <[email protected]> wrote:
>>> Perhaps you mean characteristics. See -help extended_fcn-.
>>>
>>> Nick
>>> [email protected]
>>>
>>> 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
*
* 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/