Dear Allin,

I'm working on a function that involves iterative WLS in order to correct OLS estimators in the presence of outliers. As a 1st step, the function has to leave out observations with a Cook's distance (D) > 1. Cook's D can be easily computed from the leverage series, what I do through the following code within the function:

<hansl>
ols myY myX --quiet
... # retrieve some statistics here 
leverage --quiet --save
series l = lever
... # some code for Cook's D based on l, OLS residuals and OLS se)
</hansl>

Now, the function works smoothly...unless  a "lever" series already exists in the dataset. In that case the following error message is generated,
> l=lever
The symbol 'lever' is undefined
*** error in function robust, line 22
> series l=lever

I first suspected that this is probably due to the fact that before executing my function I had already saved a lever series through the "leverage" command. So, I deleted the existing "lever" series and successfully re-run the function. 
Then, I created a new "series lever = normal(0,1)" which obviously has nothing to do with the "leverage" command. Re-run the function...and the same error came out. Deleted the "lever" series and the function runs perfectly.

Is there anything I'm missing here?

Best,
Artur