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/