Announcement

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

  • Warning: Not all pandas column names were valid Stata variable names (Python)

    Hello, all,

    I'm using Stata 17 to execute the command c_ml_stata, which makes use of Python in the background to run machine learning models. Though I can get results from my code, I do get the following text in red:

    Not all pandas column names were valid Stata variable names.
    The following replacements have been made:

    0 -> _0
    1 -> _1
    2 -> _2

    If this is not what you expect, please make sure you have Stata-compliant
    column names in your DataFrame (strings only, max 32 characters, only
    alphanumerics and underscores, no Stata reserved words)

    warnings.warn(ws, InvalidColumnName)



    How do I fix this issue with the InvalidColumnName? I just hate all that red text and don't want it to be saved to a log file with the output.

    Thanks,
    DDT
    Last edited by David Torres; 16 Dec 2021, 15:11.

  • #2
    c_ml_stata is from SSC (FAQ Advice #12).

    How do I fix this issue with the InvalidColumnName? I just hate all that red text and don't want it to be saved to a log file with the output.
    You can add capture before the command, but this may hide other substantive errors that may exist. In essence, the variables created by the command do not have valid Stata names (in this case, they start with numbers). Therefore, Stata puts an underscore before the variable name to make them valid names.

    Code:
    capture c_ml_stata
    See

    Code:
    help capture

    Comment


    • #3
      My reading of the question is that if you want to avoid this message from Stata, one fix lies outside Stata. Isn't this what the message is telling you?

      Comment


      • #4
        Thanks for your responses, gentleman.

        No, I didn't originally read the message the way you do, Mr. Cox. Thanks for that. In any case, since Python has been integrated and can be run within Stata, I thought someone on the list might be able to assist me. Seems I will need to examine how pandas names columns when Stata is calling it up.

        For now, let me see what I get with Musau's advice.

        Cheers,
        DT

        Comment

        Working...
        X