Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: searching the notes


From   Roger Harbord <roger.harbord@bristol.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: searching the notes
Date   Wed, 04 Aug 2004 11:57:04 +0100

Thanks Nick, i hadn't spotted that the limit on string expressions length bites here - of course notes can be a lot longer than variable labels, so it didn't matter in -lookfor-.

That particular limit is about the most frustrating in practice : I'm happy to limit my search string to 80 chars, but it appears to me that to allow case-insensitive searching of long notes for strings that include spaces, as i desire, i'm going to have to split each note into chunks of 80 characters and apply lower() to each then combine into a macro (being careful to avoid string operators or functions).

This is quickly getting more complicated than i have time to program right now, sorry all...

Roger.


--On 04 August 2004 10:40 +0100 Nick Cox <n.j.cox@durham.ac.uk> wrote:


Thanks for this. I think you should change the -index()-
calls back again. I didn't spell it out but I didn't use -index()-
because of the limit on the length of a string expression.

Similarly, the calls to -lower()- are a little dangerous. It would be safer
to cycle through the words of the argument and feed them to -lower()-
individually. Admittedly, it seems unlikely that the search string
will hit the limit on string expressions.

Other than that, you are running with this program,
so you should feel free to make yourself the first author
and so write the help file....

I like the idea of trying to persuade StataCorp to add this ability
to -lookfor-.

Nick
n.j.cox@durham.ac.uk

-----Original Message-----
From: Roger Harbord [mailto:roger.harbord@bristol.ac.uk]
Sent: 04 August 2004 10:24
To: statalist@hsphsun2.harvard.edu; Nick Cox
Subject: RE: searching the notes


Many thanks Nick for astoundingly quick program writing and
memory of past
threads. I'm afraid i didn't follow that thread on 11 May and
i've found
searching Statalist archives is often pretty hopeless in
practice unless you
can remember something of a thread to narrow things down
(just try searching
for "notes"...  234 results is too much for me esp. as most
of them seem to be
returned inappropriately - e.g. "notes" appears only in
subject of the "Next
by Date" message!).

In testing -searchnotes- i found that parsing with -syntax
name- wasn't ideal
in that it prevented me searching for e.g. "g/L" or "protein
C". Also I'd
prefer it to be case insensitive, like -lookfor- (i just found Dan
Blanchette's -lookforit- on SSC which allows a more flexible
approach but
haven't attempted that). I've stolen some code from the
built-in lookfor.ado
and ended up with the code below. -lookfor- uses -index-
instead of -substr
local- which seems more elegant but i can't take any credit for that
obviously. Unlike -lookfor- the code below only searches for
one string at a
time and does the same thing whether or not that string is in
quotes. No
particular reason other than that's what i usually want
myself and the
behaviour of -lookfor- is a bit more complex to program.

However personally i'd find it more convenient if this was
part of the
official -lookfor- (maybe with a -,notes- option) if
StataCorp are listening
and happen to think it worthwhile..

Roger.
----------------------------------------------------
Roger Harbord     mailto:roger.harbord@bristol.ac.uk
Department of Social Medicine, University of Bristol

*! NJC / RMH 1.0.1 4 Aug 2004
program searchnotes
version 8

	if `"`*'"' == "" {
		di as err "nothing to search for"
		exit 198
		}

	local what = lower(`"`*'"')
	
	local nnotes "`: char _dta[note0]'"
	if "`nnotes'" != "" {
		forval i = 1/`nnotes' {
			local char : char _dta[note`i']
			if index(lower(`"`char'"'),`"`what'"')  {
				di as res "_dta: " as txt `"`char'"'
				}
			}	
		}
	
	foreach v of var * {
		local nnotes "`: char `v'[note0]'"
		if "`nnotes'" != "" {
			forval i = 1/`nnotes' {
				local char : char `v'[note`i']
				if
index(lower(`"`char'"'),`"`what'"')  {
					di as res "`v': " as
txt `"`char'"'
					}
				}
			}
		}
end



--On 03 August 2004 19:55 +0100 Nick Cox <n.j.cox@durham.ac.uk> wrote:

> This would seem approachable
> as a variation on various programs
> posted on 11 May, e.g.
>
> *! NJC 1.0.0 3 Aug 2004
> program searchnotes
> 	version 8
> 	syntax name(name=what)
> 	
> 	local nnotes "`: char _dta[note0]'"
> 	if "`nnotes'" != "" {
> 		forval i = 1/`nnotes' {
> 			local char : char _dta[note`i']
> 			local WHAT : ///
> 		subinstr local char `"`what'"' `"`what'"',
count(local n)
> 			if `n' {
> 				di as res "_dta: " as txt `"`char'"'
> 			}
> 		}	
> 	}
>
> 	foreach v of var * {
> 		local nnotes "`: char `v'[note0]'"
> 		if "`nnotes'" != "" {
> 			forval i = 1/`nnotes' {
> 				local char : char `v'[note`i']
> 				local WHAT : ///
> 		subinstr local char `"`what'"' `"`what'"',
count(local n)
> 				if `n' {
> 					di as res "`v': " as
txt `"`char'"'
> 				}
> 			}
> 		}
> 	}
> end
>
> I'd appreciate a more elegant method of counting...
>
> Nick
> n.j.cox@durham.ac.uk
>
>> -----Original Message-----
>> From: owner-statalist@hsphsun2.harvard.edu
>> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of
>> Roger Harbord
>> Sent: 03 August 2004 19:29
>> To: Statalist; tech-support@stata.com
>> Subject: st: searching the notes
>>
>>
>> Is there any way of searching all the -notes- for a given
>> string?  I find
>> -lookfor- very useful when dealing with datasets with many
>> variables but it
>> would be even more useful if it had a -, notes- option to
>> allow searching of
>> the notes attached to the variables too. Alternatively maybe
>> if -notes list-
>> had a -, find(string)- option..?
>>
>> I realise that you need to have a lot of notes in your
>> dataset to find this
>> useful - we do here as our database manager has set up a
>> clever system (don't
>> ask me how it works) to export from Access to Stata so each
>> Field Description
>> in Access becomes a note attached to that variable in Stata.
>> (The Field
>> Descriptions are too long to make useful variable labels and
>> often exceed the
>> limit of 80 characters for variable labels.)
>>


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index