Announcement

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

  • predictnl and factor variables

    Dear All,

    suppose I have the following:

    Code:
    logit Y X1 X2 X3 i.COUNTRY i.YEAR, cluster(S003)
    After the estimation I need to calculate a value using the following:

    Code:
    predictnl abc=1/(1+exp(-(_b[X1]*X1+_b[i.COUNTRY]*I.COUNTRY+_b[i.YEAR]*i.YEAR)))
    So i need to exclude some of the regressors. I have many countries and many years, so I tried to use factor variables, hoping that predictnl could recognize it. Apparently, this is not the case. So is there any way to use factor variable within predictnl? I need to calculate several of those values above and it is quite annoying to write down all the coefficients/variables associated to the country and year dummies. On the side, using factor notation, I need to check every time which country and year has been dropped to avoid collinearity.

    Thanks in advance for the help.

  • #2
    As long as you know the non-linear transformation required, you do not need to type any long expressions. Contrast this to the predict syntax where you never type in an expression as the linear transformation is unique.

    Code:
    webuse lbw
    probit low lwt smoke ptl ht
    predictnl phat = normal(_b[_cons] +_b[ht]*ht +_b[ptl]*ptl +_b[smoke]*smoke+ _b[lwt]*lwt), se(phat_se)
    predictnl phat2 = normal(xb(low)), se(phat_se2)
    assert phat==phat2
    assert phat_se==phat_se2

    Note that you can difference the sum of the excluded regressors multiplied by their coefficients. Example:


    Code:
    webuse lbw
    probit low lwt smoke ptl ht
    predictnl phat3 = normal(_b[_cons] +_b[ht]*ht + _b[lwt]*lwt)
    predictnl phat4 = normal(xb(low)-_b[ptl]*ptl -_b[smoke]*smoke)
    assert phat3==phat4
    Last edited by Andrew Musau; 16 Sep 2020, 10:38.

    Comment


    • #3
      Andrew Musau Thanks a lot. That saved me a lot of time.

      Comment

      Working...
      X