mattiasnordin / StataEditor

Stata Editor for Sublime Text 3
47 stars 18 forks source link

Locals not functioning #15

Open Yuji-Shimohira-Calvo opened 7 years ago

Yuji-Shimohira-Calvo commented 7 years ago

Hi @mattiasnordin,

First of all many thanks for all this. I've been trying StataEditor lately and I'm very happy with it. However, I noticed something that slows down my workflow quite considerably (I don't know if it's a problem with Stata Automation or with StataEditor). The issue is related to local macros.

Let's say you have coded the following:

local path "C:/Users/Name/Folder/Another_Folder"
log using "`path'/my_log_file.txt", text replace

If you run these two lines at the same time from Sublime using StataEditor everything will be okay. However, if you run them one by one the second line will not figure out `path'. I guess this problem has to do with the way Stata's locals and Stata Automation work and not with StataEditor, but I thought it was worth-asking this here just in case.

Many thanks!

mattiasnordin commented 7 years ago

Hi! This is related to how Stata has chosen to implement locals. You will get the exact same behavior in Stata's own editor. If you want the macro to keep living, you will have to use globals instead (though I would in general not recommend it).

Mattias

Yuji-Shimohira-Calvo commented 7 years ago

Thanks for your reply. That's what I thought after finding the issue. For some reason I thought that Stata Automation (and StataEditor) might work through the commands window (like Stata in iPython notebooks). In that case locals would persist throughout the session because they were technically typed in the commands window, correct?

mattiasnordin commented 7 years ago

Yes, that would probably be correct. And in principle I could do that, but I have chosen to go through sending a do-file instead, so as to mimic Stata's do-file editor.

As an aside, this is a case where ST:s multiple selection comes in very handy. Often you define locals at the top of a file, but want to execute some commands later. In those cases I use multiple selections all the time.

Yuji-Shimohira-Calvo commented 7 years ago

Thanks a lot for your replies, @mattiasnordin. Keep up the good work with this package!

mattiasnordin commented 7 years ago

Thanks!