ticoneva / pystata-kernel

Jupyter kernel for Stata based on pystata
GNU General Public License v3.0
13 stars 6 forks source link

use -tempvar- for browse magic selection variables #13

Closed ideabucket closed 2 years ago

ideabucket commented 2 years ago

I've tweaked the SelVar class to use Stata's tempvar command to name the variables. This has a couple of advantages:

Since tempvars are syntactic sugar for a local macro, I use sfi to fetch the value they resolve to in order to populate SelVar.varname rather than using a unique variable name on the python side of things. tempvar itself has no problem being supplied the same string again and again.

I also made a minor change to the invocation of .replace on the selection condition so it only replaces the first instance of "if", just in case there's a variable in the varlist that happens to end in those characters.

ticoneva commented 2 years ago

Using tempvar is definitely a good idea but I just wasn't sure what's the best way to get the variable name. I will try out the PR either tomorrow or on Thursday.

ticoneva commented 2 years ago

I think the clear() method is still needed, otherwise the temporary variable will show up the next time *%browse is called.