Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Global not being recognized in mmat2tex command

    Hello,

    I have defined my global and it is not being recognized in the mmat2tex command. If I use the same global with estout or esttab or other command, it works perfectly.

    If I run either line below, I get the error: file handle __000000 not found
    Code:
    mmat2tex tab using "${Oleaf}/pc11_res`y'_balance.tex", replace
    OR
    mmat2tex tab using "C:/Users/abcd/Dropbox/Apps/Overleaf/Project/Tables/pc11_res`y'_balance.tex", replace
    If I specify the directory right before mmat2tex command, it works just fine.
    Code:
    cd "C:/Users/abcd/Dropbox/Apps/Overleaf/Project/Tables/"
    mmat2tex tab using "pc11_res`y'_balance.tex", replace
    This bug is really puzzling and weird. I'd appreciate any help!
    Last edited by Ei Thandar Myint; 24 Jan 2023, 19:06. Reason: global

  • #2
    The mmat2tex command is a community contributed command written by Jan Ditzen and available from SSC, as you are asked to mention in the Statalist FAQ linked to from the top of the page.

    The problem is not that your global variable is not recognized by the command, since in fact Stata interprets the global variable before passing the using path to the mmat2tex command.

    Does your actual Windows username (I assume it is not "abcd") include an embedded space?

    In looking at mmat2tex.ado, I see that it consistently fails to surround path names with quotation marks, and in particular, the path name to the using file.
    Code:
    capture file open `file2' using `using' , w    text replace
    This sort of oversight coupled with a path containing an embedded space can cause problems that produce unhelpful error messages such as the one you received. And this would be consistent with the workaround you describe, where the cd command surrounds the offending portion of the path with quotation marks.

    As an aside, this is why the Statalist FAQ, which you should take a few minutes to review, tells us
    12.1 What to say about your commands and your problem

    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
    It took far more time than it should have for me to realize that the username, rather than the local macro `y', is the likely source of this problem consistent with the workaround you presented.

    While you use quotation marks in your code that calls mmat2tex, they are stripped off before the path is stored as the first argument to the program, as the examples below demonstrate.

    Other than the workaround you used, perhaps the trick in the fourth example would work for you.

    In any event this is a programming oversight that you might want to report to the author (the email address is given in the output of help mmat2tex).
    Code:
    . capture program drop gnxl
    
    . program define gnxl
      1.     args pathname
      2.     macro list _pathname
      3. end
    
    . gnxl foo
    _pathname:      foo
    
    . gnxl foo bar
    _pathname:      foo
    
    . gnxl "foo bar"
    _pathname:      foo bar
    
    . gnxl `"`"foo bar"'"'
    _pathname:      `"foo bar"'
    
    .

    Comment

    Working...
    X