Announcement

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

  • Marginal effects after the xtivreg2 command

    Hi,


    In the estimation section of my dissertation, I have an endogenous variable, "sublia", and its interactions with four weather variables of ddayHot_100, ddayMod_100, prec_cm and prec_cm2. I am using an instrumental variable "tau_final" for identification in the xtivreg2 command.

    How can I calculate the marginal effect of change in my main variable "sublia"? I am trying to derive something like "10% increase in sublia causes XX% decrease in log(yield)" at average values of weather variables, or different percentiles of weather variables.

    My code:

    Code:
    gen sublia_ddayHot = sublia * ddayHot_100
    gen sublia_ddayMod = sublia * ddayMod_100
    gen sublia_prec = sublia * prec_cm
    gen sublia_prec2 = sublia * prec2_cm
    
    gen IV_hottemp = ddayHot_100 * tau_final
    gen IV_modtemp = ddayMod_100 * tau_final
    gen IV_rain = prec_cm * tau_final
    gen IV_rain2 = prec2_cm * tau_final
    
    xtivreg2 log_yield (sublia sublia_ddayHot sublia_prec2 sublia_ddayMod sublia_prec = tau_final IV_hottemp IV_rain2 IV_modtemp IV_rain) l.yield price_received ddayMod_100 ddayHot_100 prec_cm prec2_cm corntime soybeantime, fe gmm cluster(panelID) first


    Thank you.
    Homa
    Last edited by Homa Taheri; 12 Sep 2025, 10:49.

  • #2
    Hi,

    I asked this question from the Stata Technical Services, and received the response below. It may be useful for others as well.

    "Please note that -xtivreg2- is a community-contributed command, and its
    authors provide direct support for it. You can find their contact
    information in the help file for -xtivreg2- .

    You may consider using the -xtivreg- command and calculating the
    marginal effects with -margins, dydx(sublia)- at different values of
    weather variables.

    Here is an illustrative example:"

    Code:
    **********************
    
    /*generate example data*/
    clear
    set obs 20
    set seed 1234
    generate panelID = _n
    expand 10
    bysort panelID: generate year = 1970+_n
    
    generate ddayHot_100 = rnormal()
    generate tau_final = rnormal()
    gen IV_hottemp = ddayHot_100 * tau_final
    gen price = rnormal()
    
    gen sublia = 1 + tau_final + IV_hottemp + price ///
    + ddayHot_100 + rnormal()
    
    gen sublia_dayHot = 1 + tau_final + IV_hottemp  ///
    + price + ddayHot_100 + rnormal()
    
    generate yield = price + ddayHot_100 - sublia   ///
    - sublia_dayHot + rnormal()
    
    /*xtivreg model*/
    xtset panelID
    
    xtivreg yield price ddayHot_100                ///
    (sublia sublia_dayHot = tau_final IV_hottemp), ///
    fe first vce(cluster panelID)
    
    /*marginal effects*/
    margins, dydx(sublia) at((p25) ddayHot_100)    ///
    at((mean) ddayHot_100) at((p75) ddayHot_100)
    
    **********************
    Last edited by Homa Taheri; 12 Sep 2025, 13:22.

    Comment


    • #3
      I just posted on the Stata 20 wish list why Stata should allow factor notation and interactions, squares, and so on in xtivreg when the interaction terms are endogenous. Having to created them is clunky and precludes application of margins afterward. The same logic for ivregress can be applied to xitvreg.

      Homa: I noticed one potential point of misunderstanding. You say you are interested in something like "a 10% increase in sublia causes XX% decrease in log(yield)." But there are two issues. First, it won't be an XX% decrease in log(yield), it will be an XX% decrease in yield. (We use log(yield) to get that interpretation.) Secondly, even without the interaction, you have to be careful about how you are interpreting the change in sublia. Is this variable in logs? If not, then you won't be changing it be a certain percent when interpreting its coefficient. I suspect sublia is measured as a percent (say, 20.3 for 20.3 percent). Then it will be a percentage point change in sublia, not a percentage change.

      Comment


      • #4
        Originally posted by Jeff Wooldridge View Post
        I just posted on the Stata 20 wish list why Stata should allow factor notation and interactions, squares, and so on in xtivreg when the interaction terms are endogenous. Having to created them is clunky and precludes application of margins afterward. The same logic for ivregress can be applied to xitvreg.

        Homa: I noticed one potential point of misunderstanding. You say you are interested in something like "a 10% increase in sublia causes XX% decrease in log(yield)." But there are two issues. First, it won't be an XX% decrease in log(yield), it will be an XX% decrease in yield. (We use log(yield) to get that interpretation.) Secondly, even without the interaction, you have to be careful about how you are interpreting the change in sublia. Is this variable in logs? If not, then you won't be changing it be a certain percent when interpreting its coefficient. I suspect sublia is measured as a percent (say, 20.3 for 20.3 percent). Then it will be a percentage point change in sublia, not a percentage change.
        Hi Professor Woodridge,

        It is correct; sublia is not logarithmic, and it is of "percenr" nature. Sublia captures the "share of subsidy per dollar of liability". I actually had not paid attention to this point. Thank you so much for your remark.

        Comment

        Working...
        X