Announcement

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

  • How to test the coefficients of a variable across different models

    Dear All

    I am trying to estimate the following equations and test whether the coefficients varies across the three models

    use data.dta
    1. reghdfe ln_Import i.EU i.Contig controls, absorb( year product) vce(robust)
    estimates store Value1


    use data.dta
    keep if organic=1
    1. reghdfe ln_Import i.EU i.Contig controls, absorb( year product) vce(robust)
    estimates store Value2

    ​​​​​​​use data.dta
    keep if organic=0
    1. reghdfe ln_Import i.EU i.Contig controls, absorb( year product) vce(robust)
    estimates store Value3

    I want to test whether the coefficients of EU and Contig differ across the three models. The models 2) and 3) are estimated using subdata of the 1).
    I have read this thread, which is very helpful. My understanding is that it is better I estimate one model with interactions and the coefficient of the interaction term becomes the differences, like
    1. reghdfe ln_Import i.EU i.Contig i.EU##organic i.Contig##organic controls, absorb( year product) vce(robust)
    However, for the purpose of my learning, I would like to know why my approach is wrong? And if it is not wrong to compare the coefficients across the three models, can you suggest how to test whether the coefficients are different? I have already tried the following

    suest Value2 Value3
    test [Value2_mean]EU_Member=[Value3_mean]EU_Member

    But it didn’t work. I got the error message
    ". . suest Value2 Value3
    estimation sample of the model saved under Value2 could not be restored
    r(198);

    end of do-file

    r(198);"


    I also used reg instead of reghdfe, and stated the FE as i.year i.product instead of absorb(.)

    ​​​​​​​use data.dta
    1. reg ln_Import i.EU i.Contig controls, i.year i.product
    estimates store Value1

    ​​​​​​​use data.dta
    keep if organic=0
    1. reg ln_Import i.EU i.Contig controls, i.year i.product
    estimates store Value2

    ​​​​​​​use data.dta
    keep if organic=1
    1. reg ln_Import i.EU i.Contig controls, i.year i.product
    estimates store Value3

    suest Value2 Value3, vce(robust)
    test [Value2_mean]EU_Member=[Value3_mean]EU_Member

    This too did not work, I got the error message “product: factor variable base category conflict r(198)”. But when I dropped the product FE (i.product), everything worked as expected. I need to include the product FE. Any guidance? Thank you in advance for the support.

  • #2
    estimation sample of the model saved under Value2 could not be restored
    You are getting this message because when you are running the -suest- command, the data in memory is only the subset of your data set with organic = 0, and so -suest- cannot find the appropriate data for Value 2, which was calculatd from the subset with organic = 1. The correct way to set this up would keep the entire data set in memory at all times:

    Code:
    use data.dta,
    
    reghdfe ln_Import i.EU i.Contig controls if organic = 0, absorb( year product)
    estimates store value2
    
    reghdfe ln_Import i.EU i.Contig controls if organic = 1, absorb( year product)
    estimates store value3
    
    suest value2 value3, vce(robust)
    Note, by the way, that you cannot include the -vce(robust)- option on the -reghdfe- commands here: you use ordinary vce there, and introduce -vce(robust)- in the -suest- command.

    product: factor variable base category conflict r(198)
    This, too, arose because you changed the data set between the two estimations. This resulted in different values of variable product being left in the data set, and that led to different choices of the base (omitted) category of factor. To fix this, again, you need to use -if- clauses rather than -keep if- to restrict the regressions to the subsets you want. You also need to pick a value of product that will be found in both the organic = 0 and organic = 1 data sets. For purposes of illustration, I here assume that product 5 will be found in both levels of the organic variable. Then the set up would be:

    Code:
    use data.dta, clear
    
    reg ln_Import i.EU i.Contig controls if organic == 0, i.year ib5.product
    estimates store value2
    
    reg ln_Import i.EU i.Contig controls if organic == 1, i.year ib5.product
    estimates store value3
    
    suest value2 value3, vce(robust)
    Note: If there is no value of product that occurs in both the organic == 0 and organic == 1 subsets, then I don't believe this method can be used for your problem.

    Comment


    • #3
      Dear Clyde Schechter, thank you very much for the helpful response.

      When I use reghdfe and followed your instructions, the "suest" still did not work. I got an error message:

      " suest Value2 Value3, vce(r)
      unable to generate scores for model Value2
      suest requires that predict allow the score option
      r(322);"

      I learned that the suest command does not work with reghdfe.

      However, when I use reg and specify the base category as you indicated, the "suest value2 value3, vce(robust)" did not return error (so I assume it is running correctly), except that it is taking forever to run, since my product FE(which is based on tariff number) has over 2000 categories. Do you have a suggestion? Thank you.

      Comment


      • #4
        Ah, yes, I had forgotten that -suest- does not support -reghdfe-. Sorry about that.

        As for the long run-time on the -reg- approach, with 2000 products, that is to be expected, and I don't know of anyway to speed it up.

        As a practical matter, what I recommend is that you not use the -suest- approach in the first place. Use the interaction approach that you referred to in your original post. It will be quick and will give you the results you need. You can streamline the code a little bit (though it won't effect execution time) to:
        Code:
        reghdfe ln_Import  i.(Contig EU)##i.organic controls, absorb( year product) vce(robust)
        You don't need to include separate uninteracted terms for Contig and EU, because the ## operator creates them for you. And the i. operator can be applied to a group of variables all at once by wrapping them inside parentheses, as I've done here.

        Comment


        • #5
          Thank you very much for the support Clyde Schechter

          Comment

          Working...
          X