Announcement

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

  • ml command for logit panel data

    Hi All:

    I am new to ml command. Before writing a more complicated code, I am testing the code on logit panel data first.

    I first reshape my long format into wide format. I have six waves.

    The following is my code:
    Code:
     program define mylogit
    
        args        lnf    b1_w1 b1_w2 b1_w3 b1_w4 b1_w5 xb1_w6 
    
        quietly replace `inf' =    y3*ln(invlogit(`b1_w1')+(1-y3)*ln(invlogit(-`b1_w1')+y4*ln(invlogit(`b1_w2')+(1-y4)*ln(invlogit(-`b1_w2')+y5*ln(invlogit(`b1_w3')+(1-y5)*ln(invlogit(-`b1_w3')+y6*ln(invlogit(`b1_w4')+(1-y6)*ln(invlogit(-`b1_w4')+y7*ln(invlogit(`b1_w5')+(1-y7)*ln(invlogit(-`b1_w5')+y8*ln(invlogit(`b1_w6')+(1-y8)*ln(invlogit(-`b1_w6')
    
    end 
    ml model lf mylogit (xb1_w1: $xvar1) (xb1_w2: $xvar2) (xb1_w3: $xvar3) (xb1_w4: $xvar4) (xb1_w5: $xvar5) (xb1_w6: $xvar6) 
    ml maximize
    When I ran it, it shows 'varlist required' in 'inf' function.

    However, I could not figure out where the problem is.

    Anyone who can help me to point out where the issue is?

    Many thanks,

    Connie

  • #2
    It might help if you used dataex to post an excerpt of your data so we had a replicable example.

    Barring that have $xvar1 etc been defined before running your code?
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://academicweb.nd.edu/~rwilliam/

    Comment


    • #3
      Thank you, William. I have unbalanced panel data. I only tried with two explanatory variables. The unbalance panel created missing values in one row, which makes my estimation only focus on observation with no missing values. I think the bug is because of unbalanced panel. But I have not come up with other solution.

      My data looks like this: (I did not show age here, it messes the format)

      [CODE]
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(y3 timerush3 y4 timerush4 y5 timerush5 y6 timerush6 y7 timerush7 y8 timerush8)
      1 1 . . 0 2 . . 0 4 . .
      . . 0 4 0 5 0 2 0 2 . .
      . . . . 1 1 1 2 0 4 . .
      . . . . . . 0 2 0 3 1 2
      0 3 . . 1 1 . . . . . .
      . . . . . . 0 3 0 2 0 5
      . . 1 4 1 3 1 4 1 5 1 5
      0 3 . . 0 4 . . . . . .
      . . . . . . 0 3 . . . .
      . . . . . . 0 5 . . . .
      . . . . . . 1 2 . . 0 5
      0 1 0 1 . . 0 1 0 1 0 2
      0 3 1 2 1 3 1 3 . . . .
      . . . . . . 0 4 . . . .
      . . . . 1 2 1 2 . . . .
      0 2 0 2 . . . . . . . .
      . . 1 2 1 2 1 3 1 3 1 3
      . . . . . . 0 3 0 2 0 3
      . . 1 2 . . 1 3 . . . .
      1 4 1 4 . . 0 3 1 2 . .
      . . . . 1 2 . . . . . .
      1 4 1 5 0 5 . . 0 5 . .
      . . . . . . . . . . 1 3
      . . 1 2 1 1 1 2 1 2 1 2
      0 2 0 2 0 2 0 3 . . . .
      . . . . 0 5 . . 0 5 . .
      . . . . . . 0 4 . . . .
      . . 1 1 1 4 1 2 . . . .
      . . 0 5 0 4 0 4 . . . .
      . . 1 3 1 2 1 3 1 2 1 2
      . . 1 1 . . . . . . . .
      . . 0 5 0 4 . . . . . .
      1 2 1 2 . . 1 2 1 3 . .
      0 2 0 3 0 2 . . . . . .
      0 3 . . . . . . . . . .
      . . . . . . 0 5 0 4 0 5
      . . . . 0 2 . . . . . .
      . . . . 1 2 0 3 . . 0 5
      . . . . . . 0 2 . . . .
      . . 1 2 . . . . . . . .
      . . . . 1 2 1 3 1 3 . .

      My code partly works:

      Code:
      global xvar3 "age3 timerush3" 
      global xvar4 "age4 timerush4" 
      global xvar5 "age5 timerush5"  
      global xvar6 "age6 timerush6" 
      global xvar7 "age7 timerush7"
      global xvar8 "age8 timerush8"
      
      capture program drop mylogit
      
      program define mylogit
                args lnf b_w3 b_w4 b_w5 b_w6 b_w7 b_w8
                
                quietly replace `lnf' = y3*ln(invlogit( `b_w3'))+(1-y3)*ln(invlogit( -`b_w3'))+y4*ln(invlogit( `b_w4'))+(1-y4)*ln(invlogit( -`b_w4'))+y5*ln(invlogit( `b_w5'))+(1-y5)*ln(invlogit( -`b_w5'))+y6*ln(invlogit( `b_w6'))+(1-y6)*ln(invlogit( -`b_w6'))+y7*ln(invlogit( `b_w7'))+(1-y7)*ln(invlogit( -`b_w7'))+y8*ln(invlogit( `b_w8'))+(1-y8)*ln(invlogit( -`b_w8'))          
                
                                                      
      end
        
      ml model lf mylogit (xb_w3:$xvar3)(xb_w4:$xvar4)(xb_w5:$xvar5)(xb_w6: $xvar6)(xb_w7: $xvar7)(xb_w8:$xvar8)
      
      ml maximize



      Comment

      Working...
      X