Announcement

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

  • r(322); Variable not found in list of covariates

    Hi all,

    Long-time user, first-time poster.

    I am using Stata 17/SE on Mac and I am running into an r(322) error when I run margins post-Logistic regression. I've run similar code before and have not had any issues previously, so I am really unsure what is causing it.

    For context, I am working with tennis data. Where 'tb' refers to a tiebreak and 'ppw' refers to the percentage of points won. Most variables are dummies, aside from a few that indicate score/number of points won/etc.

    My code is as follows:
    Code:
    logistic set2win_t i.set1ppw_tX set1_tb_t if team_unique == 1 & set1tb_dum == 1 & set2tb_dum == 0 & gender == 0, cluster(match_id)
    test i45.set1ppw_tX == i55.set1ppw_tX
    levels set1ppw_tX, local(lvs)
    margins, at(set1tb_ppw_t=(`lvs'))
    Where set1ppw_tX is a generated int (of total percentage of points won):
    Code:
    gen int set1ppw_tX = round(set1tb_ppw_t, 0.05)*100
    This is an example of my data:
    Code:
           +-------------------------------------------------------------------------------------+
           | match_id   team_u~e   gender   set1tb~m   set2tb~m   set2wi~t   set1pp~X   set1_t~t |
           |-------------------------------------------------------------------------------------|
    12817. |     3205          1        0          1          0          0         55          8 |
    12818. |     3205          .        0          1          0          0         55          8 |
    12819. |     3205          1        0          1          0          1         45          6 |
    12820. |     3205          .        0          1          0          1         45          6 |
           |-------------------------------------------------------------------------------------|
    14385. |     3597          1        1          1          0          0         30          3 |
    14386. |     3597          .        1          1          0          0         30          3 |
    14387. |     3597          1        1          1          0          1         70          7 |
    14388. |     3597          .        1          1          0          1         70          7 |
           |-------------------------------------------------------------------------------------|
    14449. |     3613          1        1          1          0          0         35          4 |
    14450. |     3613          .        1          1          0          0         35          4 |
    14451. |     3613          1        1          1          0          1         65          7 |
    14452. |     3613          .        1          1          0          1         65          7 |
           |-------------------------------------------------------------------------------------|
    The error comes when I try to run:
    Code:
    margins, at(set1tb_ppw_t=(`lvs'))
    Am I making an obvious error here? Have I been sitting in front of Stata too long? I've run similar code before and not had any issues

    Any help is appreciated!

    ...Also I know these variables are horribly named, haha!

  • #2
    Nikita:
    welcome to this forum.
    Please use -dataex- to share an excerpt/example of your dataset. Thanks.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi Carlos,

      Thanks for your reply.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(match_id team_unique gender set1tb_dum set2tb_dum set2win_t) int set1ppw_tX float set1_tb_t
      3205 1 0 1 0 0 55  8
      3205 . 0 1 0 0 55  8
      3205 1 0 1 0 1 45  6
      3205 . 0 1 0 1 45  6
      3597 1 1 1 0 0 30  3
      3597 . 1 1 0 0 30  3
      3597 1 1 1 0 1 70  7
      3597 . 1 1 0 1 70  7
      3613 1 1 1 0 0 35  4
      3613 . 1 1 0 0 35  4
      3613 1 1 1 0 1 65  7
      3613 . 1 1 0 1 65  7
      3628 1 1 1 0 0 40  5
      3628 . 1 1 0 0 40  5
      3628 1 1 1 0 1 60  7
      3628 . 1 1 0 1 60  7
      3629 1 1 1 0 0 35  4
      3629 . 1 1 0 0 35  4
      3629 1 1 1 0 1 65  7
      3629 . 1 1 0 1 65  7
      3660 1 1 1 0 1 45 13
      3660 . 1 1 0 1 45 13
      3660 1 1 1 0 0 55 15
      3660 . 1 1 0 0 55 15
      3661 1 1 1 0 1 20  2
      3661 . 1 1 0 1 20  2
      3661 1 1 1 0 0 80  7
      3661 . 1 1 0 0 80  7
      3677 1 1 1 0 1 90  7
      3677 . 1 1 0 1 90  7
      3677 1 1 1 0 0 15  1
      3677 . 1 1 0 0 15  1
      3692 1 1 1 0 1 70  7
      3692 . 1 1 0 1 70  7
      3692 1 1 1 0 0 30  3
      3692 . 1 1 0 0 30  3
      3700 1 1 1 0 0 35  4
      3700 . 1 1 0 0 35  4
      3700 1 1 1 0 1 65  7
      3700 . 1 1 0 1 65  7
      3708 1 1 1 0 1 40  5
      3708 . 1 1 0 1 40  5
      3708 1 1 1 0 0 60  7
      3708 . 1 1 0 0 60  7
      3710 1 1 1 0 1 60  7
      3710 . 1 1 0 1 60  7
      3710 1 1 1 0 0 40  5
      3710 . 1 1 0 0 40  5
      3726 1 1 1 0 0 40  5
      3726 . 1 1 0 0 40  5
      3726 1 1 1 0 1 60  7
      3726 . 1 1 0 1 60  7
      3731 1 1 1 0 1 20  2
      3731 . 1 1 0 1 20  2
      3731 1 1 1 0 0 80  7
      3731 . 1 1 0 0 80  7
      3738 1 1 1 0 0 30  3
      3738 . 1 1 0 0 30  3
      3738 1 1 1 0 1 70  7
      3738 . 1 1 0 1 70  7
      3739 1 1 1 0 1 80  7
      3739 . 1 1 0 1 80  7
      3739 1 1 1 0 0 20  2
      3739 . 1 1 0 0 20  2
      3741 1 1 1 0 1 70  7
      3741 . 1 1 0 1 70  7
      3741 1 1 1 0 0 30  3
      3741 . 1 1 0 0 30  3
      3745 1 1 1 0 0 70  7
      3745 . 1 1 0 0 70  7
      3745 1 1 1 0 1 30  3
      3745 . 1 1 0 1 30  3
      3751 1 1 1 0 1 20  2
      3751 . 1 1 0 1 20  2
      3751 1 1 1 0 0 80  7
      3751 . 1 1 0 0 80  7
      3769 1 1 1 0 0 70  7
      3769 . 1 1 0 0 70  7
      3769 1 1 1 0 1 30  3
      3769 . 1 1 0 1 30  3
      3770 1 1 1 0 1 70  7
      3770 . 1 1 0 1 70  7
      3770 1 1 1 0 0 30  3
      3770 . 1 1 0 0 30  3
      3777 1 1 1 0 0 45  9
      3777 . 1 1 0 0 45  9
      3777 1 1 1 0 1 55 11
      3777 . 1 1 0 1 55 11
      3786 1 1 1 0 0 80  7
      3786 . 1 1 0 0 80  7
      3786 1 1 1 0 1 20  2
      3786 . 1 1 0 1 20  2
      3796 1 1 1 0 1 45  9
      3796 . 1 1 0 1 45  9
      3796 1 1 1 0 0 55 11
      3796 . 1 1 0 0 55 11
      3801 1 1 1 0 0 55  8
      3801 . 1 1 0 0 55  8
      3801 1 1 1 0 1 45  6
      3801 . 1 1 0 1 45  6
      end


      Comment


      • #4
        Nikita:
        the overridding issue with your example seems to rest on perfect prediction:
        Code:
        . logistic set2win_t i.set1ppw_tX set1_tb_t if team_unique == 1 & set1tb_dum == 1 & set2tb_dum == 0 & gender == 0, cluster(match_id)
        outcome = set1ppw_tX > 0 predicts data perfectly
        r(2000);
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          I did notice that when I run the code using the excerpt.
          The logit uses 62,000 observations and the results are typical of what I would expect to see...

          Here is another dataex that works when I try it:
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(match_id team_unique gender set1tb_dum set2tb_dum set2win_t) int set1ppw_tX float set1_tb_t
            3205 1 0 1 0 0 55  8
            3205 1 0 1 0 1 45  6
           35455 1 0 1 0 0 70  7
           35455 1 0 1 0 1 30  3
           35456 1 0 1 0 1 65  7
           35456 1 0 1 0 0 35  4
           35457 1 0 1 0 0 65  7
           35457 1 0 1 0 1 35  4
           92172 1 0 1 0 0 70  7
           92172 1 0 1 0 1 30  3
           92178 1 0 1 0 1 45  7
           92178 1 0 1 0 0 55  9
           92186 1 0 1 0 1 35  4
           92186 1 0 1 0 0 65  7
           92200 1 0 1 0 0 30  3
           92200 1 0 1 0 1 70  7
           92207 1 0 1 0 1 90  7
           92207 1 0 1 0 0 15  1
           92224 1 0 1 0 0 30  3
           92224 1 0 1 0 1 70  7
           92225 1 0 1 0 1 90  7
           92225 1 0 1 0 0 15  1
           95254 1 0 1 0 1 65  7
           95254 1 0 1 0 0 35  4
           95257 1 0 1 0 1 65  7
           95257 1 0 1 0 0 35  4
           95262 1 0 1 0 1 90  7
           95262 1 0 1 0 0 15  1
           95278 1 0 1 0 0 30  3
           95278 1 0 1 0 1 70  7
           95298 1 0 1 0 1 55  8
           95298 1 0 1 0 0 45  6
          124732 1 0 1 0 0 15  1
          124732 1 0 1 0 1 90  7
          124736 1 0 1 0 0 80  7
          124736 1 0 1 0 1 20  2
          124737 1 0 1 0 1 90  7
          124737 1 0 1 0 0 15  1
          124738 1 0 1 0 1 20  2
          124738 1 0 1 0 0 80  7
          124743 1 0 1 0 0 40  5
          124743 1 0 1 0 1 60  7
          124746 1 0 1 0 0 60  7
          124746 1 0 1 0 1 40  5
          124753 1 0 1 0 0 65  7
          124753 1 0 1 0 1 35  4
          124761 1 0 1 0 1 40  5
          124761 1 0 1 0 0 60  7
          141361 1 0 1 0 1 70  7
          141361 1 0 1 0 0 30  3
          141374 1 0 1 0 0 60  7
          141374 1 0 1 0 1 40  5
          141404 1 0 1 0 1 45  6
          141404 1 0 1 0 0 55  8
          141412 1 0 1 0 0 20  2
          141412 1 0 1 0 1 80  7
          144299 1 0 1 0 0 45  8
          144299 1 0 1 0 1 55 10
          144301 1 0 1 0 1 20  2
          144301 1 0 1 0 0 80  7
          144308 1 0 1 0 1 20  2
          144308 1 0 1 0 0 80  7
          144310 1 0 1 0 1 65  7
          144310 1 0 1 0 0 35  4
          144318 1 0 1 0 1 45  7
          144318 1 0 1 0 0 55  9
          144322 1 0 1 0 1 60  7
          144322 1 0 1 0 0 40  5
          144342 1 0 1 0 . 40  5
          144342 1 0 1 0 . 60  7
          150763 1 0 1 0 0 70  7
          150763 1 0 1 0 1 30  3
          150764 1 0 1 0 1 80  7
          150764 1 0 1 0 0 20  2
          150775 1 0 1 0 0 55  9
          150775 1 0 1 0 1 45  7
          150804 1 0 1 0 1 65  7
          150804 1 0 1 0 0 35  4
          150811 1 0 1 0 0 45  6
          150811 1 0 1 0 1 55  8
          150833 1 0 1 0 0 30  3
          150833 1 0 1 0 1 70  7
          150869 1 0 1 0 1 40  5
          150869 1 0 1 0 0 60  7
          150870 1 0 1 0 1 60  7
          150870 1 0 1 0 0 40  5
          150880 1 0 1 0 0 40  5
          150880 1 0 1 0 1 60  7
          150896 1 0 1 0 0 65  7
          150896 1 0 1 0 0 65  7
          150915 1 0 1 0 1 70  7
          150915 1 0 1 0 0 30  3
          150916 1 0 1 0 0 35  4
          150916 1 0 1 0 1 65  7
          150921 1 0 1 0 1 40  5
          150921 1 0 1 0 0 60  7
          150930 1 0 1 0 0 60  7
          150930 1 0 1 0 1 40  5
          150932 1 0 1 0 1 30  3
          150932 1 0 1 0 0 70  7
          end

          Comment

          Working...
          X