Announcement

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

  • how to represent estimates for covariates using Mata

    I have a regression model using discrete time hazard regression. And I wanted to study the effect of modifier A (binary) and factor B(linear spline with 5 knots, represents by “B?" in below), and the interaction between A and B (represents by "B?int?" below) to the outcome y. There was 3 follow-up timepoints, so fu1, fu2, fu3 were used in the discrete time model.

    Therefore, the regression writes: cloglog y i.A B? B?int? fu1 fu2 fu3, nocon eform

    Then I want to calculate the estimates for 100 points, and use these estimates to draw a graph. And my question is highlighted in red below: I wonder to represent the coefficients for fu1, fu2, fu3 in mata structure, should I use m0? To simply my question, how to represent estimates in mata for the “covariates”.

    Here is the code I wrote:

    set obs 100

    mata:xw=st_data(.,”B?")
    mata:xn=J(100,5,0)
    mata:m0=J(100,1,0)
    mata:m1=J(100,1,1)

    mata:x0=(xw,m0,m0,xn,m0,m0,m0) // reference group
    mata:x1=(xw,m0,m0,xw,m0,m0,m0) // group 1 in A, without main effect
    mata:x2=(xw,m0,m1,xw,m0,m0,m0) // group 1 in A, with main effect
    mata:x3=(xn,m0,m0,xw,m0,m0,m0) // group 1 interaction

    Thank you very much!

  • #2
    Hi Xuan,
    If you are not set on using mata, I have recently shared a piece of code for a case like yours.
    See the code below for an example:
    Code:
    ssc install f_able
    webuse lbw, clear
     
     fgen age2=max(age-19,0)
     fgen age3=max(age-23,0)
     fgen age4=max(age-26,0)
     
     cloglog low c.(age age2 age3 age4)#smoke lwt i.race 
     f_able, nl(age2 age3 age4)
     margins smoke, at(age=(16(2)32)) nochain numerical plot
    See the paper linked at the end that explains how the command works.
    Fernando

    Comment

    Working...
    X