首页 > 解决方案 > How to make local environment same for Do File Editor as for Command/Results (to use tempfiles)

问题描述

How can I make the environment be the same for the Do File editor and the Command/Results?

What I mean is this: if one runs code from the Do File editor that defines a local (local localname localvalue), then that local is not accessible when typing in the Command window. How can I make the environment (meaning the environment as it refers to locals) the same for both the Do File editor and the Command window?

The practical reason I want to do this is that I use lots of tempfiles in my code. If I have hundreds or thousands of lines of code written up in the Do File editor, I need to copy and paste all of them into the Command window in order to access the individual tempfiles when testing out individual lines of code in the Command window. This is a bit tedious to have to do over and over.

As an example, suppose that we run this code from the Do File editor:

sysuse auto2, clear
tempfile auto
save `auto'

Then we cannot access auto from the Command window. Is it possible to change a setting in Stata that will in fact allow us to access auto?

标签: environment-variablesstatalocalenvironment

解决方案


推荐阅读