lsms-worldbank / labeller

Spot and fix common problems with variable and value labels🏷
https://lsms-worldbank.github.io/labeller/
0 stars 0 forks source link

Issuing our error before Stata fails #40

Closed arthur-shaw closed 6 months ago

arthur-shaw commented 9 months ago

@kbjarkefur , my colleague and I found a Stata bug today. Good news: Stata fixed the issue in Stata 18 in a Febuary 14th update. Bad news: the bug, a problem with handling if statements with quotes, affects one of our commands.

How should we handle this? Could we programmatically see what version the user is using and issue our own error before the command fails?

The issue arises when a Stata 18 user runs lbl_list_matching_vals. The version 18 rewrite of levelsof tries to see if if and in are both missing, but fails to anticipate the case where one or both contain a string. See some trace results from my colleague's computer

image

kbjarkefur commented 9 months ago

Stata version can be retrieved from these system locals and then use to dynamically set behavior. Test this code:

di c(stata_version)
di c(version)
di c(userversion)

version 13.1
di c(stata_version)
di c(version)
di c(userversion)

However, a think a better fix is what I have submitted in https://github.com/lsms-worldbank/labeller/pull/41.

I simply compound the pattern local string. So ustrregexm(label, "`pattern'") -> ustrregexm(label, `"`pattern'"'). I was able to reproduce the issue on my computer and the issue was resolved on my computer after this. Merge this repo if the issue goes away for you and your colleague.