Code Monkey home page Code Monkey logo

Comments (5)

SuperMayo avatar SuperMayo commented on August 18, 2024 1

Thank you for your fast answer, It now works as expected !

I agree with you about using keep and drop instead of the too specific lead and lag.

from fixest.

lrberge avatar lrberge commented on August 18, 2024

Thanks for your very clear request!

I've just released a new version of the package (0.5.0) so a few comments are in order:

  1. now collinear variables are removed on the fly, so your solution with window should work (and works).
  2. I've added the possibility to add multiple references in interactions, so you can do what you want directly there:
data(base_did)
df = base_did ; df$window = ifelse(df$period %in% 3:7 & df$treat, 1, 0)
est1 = feols(y ~ x1 + window::period | id + period, df)
#> Variables 'window:period::1', 'window:period::2' and 3 others have been removed because of collinearity (see $collin.var).
est2 = feols(y ~ x1 + treat::period(c(1:2, 8:10)) | id + period, base_did)
etable(est1, est2)
#>                                     est1                est2
#> x1                   0.9907*** (0.04843) 0.9907*** (0.04843)
#> window:period::3       -2.789** (0.8627)
#> window:period::4      -4.314*** (0.9298)
#> window:period::5       -2.502** (0.9101)
#> window:period::6        -1.725* (0.8379)
#> window:period::7          1.083 (0.7922)
#> treat:period::3                            -2.789** (0.8627)
#> treat:period::4                           -4.314*** (0.9298)
#> treat:period::5                            -2.502** (0.9101)
#> treat:period::6                             -1.725* (0.8379)
#> treat:period::7                               1.083 (0.7922)
#> Fixed-Effects:       ------------------- -------------------
#> id                                   Yes                 Yes
#> period                               Yes                 Yes
#> ___________________  ___________________ ___________________
#> Observations                       1,080               1,080
#> S.E. type: Clustered              by: id              by: id
#> R2                               0.50713             0.50713
#> Within R2                        0.33496             0.33496

The big problem is that by doing these changes I introduced bugs in coefplot (sigh)--because the automatic reference was supposed to be unitary and due to other internal quirks.
In est2, the interaction plot works:

coefplot(est2)

image

But then all the references are represented as data points.
In est1, the interaction plot throws an error. A workaround is to do a "normal" coefplot:

coefplot(est1, only.inter = FALSE, drop = "x1")

image

You can also locate the coefficients where you want on the x-axis using the argument x (in case the factors are not consecutive numbers):

coefplot(est1, only.inter = FALSE, drop = "x1", x = c(0, 3.5, 4, 4.5, 6.5, 7), xlim.add = c(-0.1,0.1))

image

Note that you still have to provide a value for the x1 that is dropped though (I'll try to fix that when I have the time).

On Your suggestions

As you noticed, the factor to be interacted with can be of any type (logical, numeric, character, factor) and can represent anything, not only time periods. So the lead and lag arguments are off the table since they are not general enough.

I think I'll introduce the two arguments keep and drop on top of the ref argument. Why? Because the meaning of what keep and drop do is explicit, intuitive, and applies to any situation.
I will also keep the ref argument to ensure a synergy with coefplot. The difference between ref and drop would be:

  • coefficients removed by ref will appear in the output of coefplot
  • coefficients removed by drop will not appear in the output of coefplot

What do you think? Would these changes be OK?

In any case, thanks a lot for the effort, very appreciated!

from fixest.

lrberge avatar lrberge commented on August 18, 2024

Great then! :-)

I'll close the issue when I add the new arguments.

from fixest.

lrberge avatar lrberge commented on August 18, 2024

That's done! Still haven't fixed the coefplot bug though, but I will soon.
Thanks again!

from fixest.

lrberge avatar lrberge commented on August 18, 2024

Fyi: just got rid of the bug when interacted variables were removed because of collinearity.

from fixest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.