Announcement

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

  • Using a global within regress

    Code:
    global wc_mvp = 10
    regress percent_funded novelty_score if wc > $wc_mvp
    returns
    invalid syntax
    r(198);
    I feel I am missing something very simple and basic, but my brain is fried. Any suggestion/help?

    I should mention
    Code:
    regress percent_funded novelty_score if wc > 10
    works fine.
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    i'm curious about this as well...
    Code:
    sysuse auto
    global x = 0
    reg price mpg length if foreign > $x
    Last edited by Øyvind Snilsberg; 17 Nov 2021, 07:27.

    Comment


    • #3
      I think = is used for assignment, == for comparison.
      In any case, the error is not with the global assignment, but rather with the regression command.
      Thank you for your help!

      Stata SE/17.0, Windows 10 Enterprise

      Comment


      • #4
        #1 works well in my Stata 16.1. I see no errors there.

        Comment


        • #5
          Here is a demonstration that the example in post #2 works as expected.
          Code:
          . sysuse auto
          (1978 automobile data)
          
          . global x = 0
          
          . reg price mpg length if foreign > $x
          
                Source |       SS           df       MS      Number of obs   =        22
          -------------+----------------------------------   F(2, 19)        =     21.03
                 Model |  99446576.4         2  49723288.2   Prob > F        =    0.0000
              Residual |  44916636.3        19  2364033.49   R-squared       =    0.6889
          -------------+----------------------------------   Adj R-squared   =    0.6561
                 Total |   144363213        21   6874438.7   Root MSE        =    1537.5
          
          ------------------------------------------------------------------------------
                 price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
          -------------+----------------------------------------------------------------
                   mpg |   -68.4809   66.64538    -1.03   0.317    -207.9713    71.00947
                length |   135.5885   32.20197     4.21   0.000     68.18903     202.988
                 _cons |  -14771.69   6626.241    -2.23   0.038    -28640.57   -902.8082
          ------------------------------------------------------------------------------
          
          .
          Perhaps you could present your problem from popst #1 similarly. As it stands, I expect the code that was actually run does not match the code that was presented in post #1. By preparing an example that demonstrates the problem and copying the commands and results from Stata's Results window, you rule out the possibility that your presentation of your problem did not correctly represent what was done.

          Comment


          • #6
            Thank you!
            As I suspected, I was missing something rather basic. The model I posted above was simplified compared to what I was actually running. In what I was trying I had a piecewise (mkspline) of wc, called wc_low and wc_high, and incredibly i had included wc_* in the model....and so stata was getting confused by the global wc_mvp
            Sorry for wasting your time.
            Last edited by Pratap Pundir; 17 Nov 2021, 07:53.
            Thank you for your help!

            Stata SE/17.0, Windows 10 Enterprise

            Comment

            Working...
            X