Eddy writes:
> I encountered an odd behavior of -capture drop-, and would appreciate
> advice.
>
> I have a program in which a variable called "resid" was created
> first, and another variable "r" was created later. Before creating
> "r", I want to make sure that there is no existing variable sharing
> the same name. So I issue
>
> capture drop r
>
> to make sure there is no "r" before it is created. The problem is,
> the above line also drops "resid" which I'd like to keep it there.
> The symptom can be illustrated as the follows.
>
> ---------- example -------------------
> . set obs 100
> obs was 0, now 100
>
> . gen resid = 1
>
> .
> . sum resid
>
> Variable | Obs Mean Std. Dev. Min
> Max
> -------------+--------------------------------------------------------
> resid | 100 1 0 1
> 1
>
> .
> . capture drop r
>
> .
> . sum resid
> no variables defined
> r(111);
>
> -------- end of example -------
>
> This is true for both Stata 7, 7SE, and 8SE. My question: Is this the
> intended behavior? Is there anyway to tell Stata to drop only those
> literally specified? Thanks.
Eddy -
I'm running fully updated Stata/SE 8.1 and do not get the same result:
. l
+----------------------+
| r1 rrr resid r |
|----------------------|
1. | 3 3 4 2 |
2. | 3 3 4 2 |
3. | 3 3 4 2 |
4. | 3 3 4 2 |
5. | 3 3 4 2 |
|----------------------|
6. | 3 3 4 2 |
7. | 3 3 4 2 |
8. | 3 3 4 2 |
9. | 3 3 4 2 |
10. | 3 3 4 2 |
+----------------------+
. capture drop r
. l
+------------------+
| r1 rrr resid |
|------------------|
1. | 3 3 4 |
2. | 3 3 4 |
3. | 3 3 4 |
4. | 3 3 4 |
5. | 3 3 4 |
|------------------|
6. | 3 3 4 |
7. | 3 3 4 |
8. | 3 3 4 |
9. | 3 3 4 |
10. | 3 3 4 |
+------------------+
As you can see, only variable r was dropped.
Perhaps you should restart Stata or be sure you have the lastest version.
Tom
*
* 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/