Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: drop in a do-file


From   "Ingo Brooks" <[email protected]>
To   [email protected]
Subject   Re: st: drop in a do-file
Date   Sun, 19 Nov 2006 17:06:01 +0100

Joe,

I think the problem should be solved by defining -km`i'- to be a
-tempname-, see -help tempname-.

Hope this helps,
Ingo


On 11/19/06, Joe Trubisz <[email protected]> wrote:
OK...that's useful, but can you explain the following sequence of
commands (some output supressed):

.infile str15 disease  v1  v2  v3  v4  v5  v6  v7  v8  v9  v10  v11
v12  v13  v14  v15  v16 using "/Users/h/ data/
CollectedBucketsL16.txt",clear

. do clusterk 4
. cap: drop km*  <--- added this as you suggest to the do file
. local low = `1' - 2
. local high = `1' + 4
. forvalues i=`low'/`high' {
   2.   cluster kmeans v1-v`1', k(`i') name(km`i')
   3.   cluster stop km`i'
   4. }

This works...but if I follow it with the same command again as in:

. do clusterk 4
. cap: drop km*
. local low = `1' - 2
. local high = `1' + 4
. forvalues i=`low'/`high' {
   2.   cluster kmeans v1-v`1', k(`i') name(km`i')
   3.   cluster stop km`i'
   4. }
km2 already defined
r(198);

. display km2
km2 not found
r(111);

If  I run it again, it works. However, if I manually drop km* (first
line below) and issue the command again, I get the following:

. drop km*     <--- I typed this in
. do clusterk 4
. cap: drop km*
. local low = `1' - 2
. local high = `1' + 4
. forvalues i=`low'/`high' {
   2.   cluster kmeans v1-v`1', k(`i') name(km`i')
   3.   cluster stop km`i'
   4. }
km2 already defined
r(198);

If I run do clusterk 4 now, it works.

Any suggestions?

TIA,
Joe


On Nov 18, 2006, at 8:56 PM, Kit Baum wrote:

> Joseph writes
>
> I am automating a bunch of commands in a do file, so I can rerun
> the do file, just changing the argument.
>
> If I have a:
>
> drop km*
>
> in my do file, the first time thru, it fails because it can't drop it.
>
> No problem, since I can run as: do clusterk 4, nostop
> and it goes fine.
>
> However, if I rerun the next time thru as: do clusterk 6, nostop,
> it fails with error number 198,
> saying that variable km2 exists. You can see that the drop works
> though, since it disappears
> from the variables window.
>
>
>
> help capture
>
>
> Kit Baum, Boston College Economics
> http://ideas.repec.org/e/pba1.html
> An Introduction to Modern Econometrics Using Stata:
> http://www.stata-press.com/books/imeus.html
>
>
> *
> *   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index