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

RE: st: RE: what is c_local?


From   David Kantor <dkantor@jhu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: RE: what is c_local?
Date   Fri, 12 Dec 2003 10:42:10 -0500

Thanks to Nick for translating the Yorkshire.

I suppose that what -c_local- does can be also done using -return- (plus some copying of values, if desired). Perhaps -c_local- was around before -return- was introduced.

This discussion reminds me of something I had experimented with recently. I have written a lot of code with commands that appended a local:

local mystuff "`mystuff' other_stuff"

and I was doing that repeatedly, incrementally appending more and more additional text onto mystuff. So I wondered whether this could be programmed. I did not succeed at the time, but just now I realized what I needed to do: the name of the local as well as the contents need to be passed separately. Here is the code:

program def append_local
syntax , name(string) contents(string) newstuff(string)
c_local `name' "`contents' `newstuff'"
end

Then you call it:

append_local, name(mystuff) contents(`mystuff') newstuff(other_stuff)

This is a bit unwieldy, and requires that you use it in a particular way. So it's not worthwhile.

I think that Statacorp might consider making a new (built-in) command to do this. It would go like ...
append_local localname "stuff_to_be_appended"

Thus, it would work just like -local-, but would append rather than replace. (Is there already something like that -- that I am ignorant of?)

(I might add that such a command might be coded so as to put the appended text right at the end, avoiding the re-evaluation and copying of the entire expression as in
-local mystuff "`mystuff' other_stuff"-,
which can become very inefficient as the length of `mystuff' grows.)

-- David


David Kantor
Institute for Policy Studies
Johns Hopkins University
dkantor@jhu.edu
410-516-5404

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