Reputation: 2374
I am not sure it is a bug, but I am unable to clear the results from the results stored r() with return clear
. ereturn clear
works at clearing the stored results in e(). results clear
also works but it clears all results.
Is there any way to clear only the stored results in r()?
The reason for that is that I am running the same program for different variables depending on some conditions. Clearing the results would make sure that the returned results are always "fresh" and not a results from the program that ran previously...
clear
sysuse auto
qui reg mpg rep78, r
* works
ereturn list
ereturn clear
ereturn list
* does not work
return list
return clear
return list // still there!
* workaround
qui reg mpg rep78, r
clear results
return list
ereturn list
Upvotes: 1
Views: 300
Reputation: 1348
It appears that the only way to clear the r()
results is to declare an rclass
program. This is both slightly unsatisfactory, and, I believe, the solution to your problem as you are concerned that the r()
results your program produces will not be fresh.
Based on this Statalist discussion the following example demonstrates this behavior, and — if you wanted to be really generous — is actually a program that clears the r()
results.
program rclassclear , rclass
return local rclassclear
end
sysuse auto , clear
quietly summarize mpg
rclassclear
return list
Notice that the documentation points out a difference between r()
and return()
under “Storing results in r()”:
r()
are the returned results andreturn()
are the results being assembled to that will be returned.return clear
clears return()
not r()
.
Upvotes: 2