Coder Social home page Coder Social logo

masaasami / pysynthdid Goto Github PK

View Code? Open in Web Editor NEW
58.0 3.0 19.0 8.72 MB

Synthetic difference in differences for Python

License: Apache License 2.0

Python 2.87% Jupyter Notebook 97.13%
python causal-inference econometrics program-evaluation policy-evaluation difference-in-differences synthetic-control evidence-based-policy evidence causality

pysynthdid's People

Contributors

masaasami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pysynthdid's Issues

Discrepancy between graph and tau estimate

Hi, thanks so much for this package! I'm really grateful to you for coding this up and building it. For one of my applications, however, I'm finding some apparent discrepancies between the graphed quantities and the reported $\tau$. For example, see the below screenshot:

Screen Shot 2023-03-07 at 6 04 53 PM

This $\tau$ seems obviously much larger than the visible difference between the graphed lines, which inverts from roughly 0.1 above control to 0.2 below control, suggesting a $\tau$ closer to -0.3.

Can you help me understand what might be causing this discrepancy? I was trying to debug by inspecting the fixed effects, but I wasn't able to see in the code where the fixed effects are stored, so had trouble understanding what might have gone amiss; I'm not sure if the plot is wrong, if $\tau$ is wrong, or if there's just something odd about the relatively sparse $\lambda$ weighting that is leading to the mismatch between the estimate and the visual pattern. I'd be happy to provide replication data if that would be helpful, thanks regardless for your attention to this.

Error when installing

`Collecting git+https://github.com/MasaAsami/pysynthdid
Cloning https://github.com/MasaAsami/pysynthdid to /tmp/pip-req-build-ey_7xzv7
Running command git clone --filter=blob:none --quiet https://github.com/MasaAsami/pysynthdid /tmp/pip-req-build-ey_7xzv7
Resolved https://github.com/MasaAsami/pysynthdid to commit 01afe33
Preparing metadata (setup.py) ... done
Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from pysynthdid==0.0.1) (1.5.3)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from pysynthdid==0.0.1) (3.7.1)
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from pysynthdid==0.0.1) (1.23.5)
Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from pysynthdid==0.0.1) (4.66.1)
Collecting sklearn (from pysynthdid==0.0.1)
Using cached sklearn-0.0.post7.tar.gz (3.6 kB)
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
Preparing metadata (setup.py) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.`

Converting tau when data is log transform

Hey! thanks for your package

I've been playing around with it as an extension of Google's CausalImpact tool.

Got a dataset with market data having different scales, so log transformation is needed. However, I couldn't transform back ATT from its value estimated from log input data to one unscaled. Which formula should I use? Also, is it possible to get confidence interval for tau?

Applying pysynthdid, obtaining homogeneous weights and no plot

I am trying to apply the code to a time series dataset I am working with. I arranged it as in the example

When I run:

'sdid = SynthDID(df_int, pre_terem, post_terem, treatment )
sdid.fit(zeta_type="base")
hat_omega_simple = sdid.estimated_params(model="sc")
hat_omega_simple'

the sc_weight is the same for all the features, at 0.027

Then when I run:

'sdid.plot(model="sc")'

I get:


TypeError Traceback (most recent call last)
Input In [139], in <cell line: 1>()
----> 1 sdid.plot(model="sc")

File ~/anaconda3/lib/python3.9/site-packages/synthdid/plot.py:12, in Plot.plot(self, model, figsize)
10 result = pd.DataFrame({"actual_y": self.target_y()})
11 post_actural_treat = result.loc[self.post_term[0] :, "actual_y"].mean()
---> 12 post_point = np.mean(self.Y_post_c.index)
14 if model == "sdid":
15 result["sdid"] = self.sdid_trajectory()

File <array_function internals>:5, in mean(*args, **kwargs)

File ~/anaconda3/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3438, in mean(a, axis, dtype, out, keepdims, where)
3436 pass
3437 else:
-> 3438 return mean(axis=axis, dtype=dtype, out=out, **kwargs)
3440 return _methods._mean(a, axis=axis, dtype=dtype,
3441 out=out, **kwargs)

File ~/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/extension.py:95, in _inherit_from_data..method(self, *args, **kwargs)
93 if "inplace" in kwargs:
94 raise ValueError(f"cannot use inplace with {type(self).name}")
---> 95 result = attr(self._data, *args, **kwargs)
96 if wrap:
97 if isinstance(result, type(self._data)):

TypeError: mean() got an unexpected keyword argument 'dtype'

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.