<jupyter_start><jupyter_text>DoWhy example on the Lalonde datasetThanks to [@mizuy](https://github.com/mizuy) for providing this example. Here we use the Lalonde dataset and apply IPW estimator to it.<jupyter_code>import os, sys
sys.path.append(os.path.abspath("../../"))

import dowhy
from dowhy.do_why import CausalModel
from rpy2.robjects import r as R
%load_ext rpy2.ipython

#%R install.packages("Matching")
%R library(Matching)<jupyter_output>R[write to console]: Loading required package: MASS

R[write to console]: ## 
##  Matching (Version 4.9-5, Build Date: 2019-03-05)
##  See http://sekhon.berkeley.edu/matching for additional documentation.
##  Please cite software as:
##   <NAME>. 2011. ``Multivariate and Propensity Score Matching
##   Software with Automated Balance Optimization: The Matching package for R.''
##   Journal of Statistical Software, 42(7): 1-52. 
##<jupyter_text>1. Load the data<jupyter_code>%R data(lalonde)
%R -o lalonde<jupyter_output><empty_output><jupyter_text>Run DoWhy analysis: model, identify, estimate<jupyter_code>model=CausalModel(
        data = lalonde,
        treatment='treat',
        outcome='re78',
        common_causes='nodegr+black+hisp+age+educ+married'.split('+'))
identified_estimand = model.identify_effect()
estimate = model.estimate_effect(identified_estimand,
        method_name="backdoor.propensity_score_weighting")
#print(estimate)
print("Causal Estimate is " + str(estimate.value))<jupyter_output>WARNING:dowhy.do_why:Causal Graph not provided. DoWhy will construct a graph based on data inputs.
INFO:dowhy.do_why:Model to find the causal effect of treatment ['treat'] on outcome ['re78']
INFO:dowhy.causal_identifier:Common causes of treatment and outcome:['U', 'age', 'educ', 'black', 'nodegr', 'married', 'hisp']
WARNING:dowhy.causal_identifier:There are unobserved common causes. Causal effect cannot be identified.<jupyter_text>Sanity check: compare to manual IPW estimate<jupyter_code>df = model._data
ps = df['ps']
y = df['re78']
z = df['treat']

ey1 = z*y/ps / sum(z/ps)
ey0 = (1-z)*y/(1-ps) / sum((1-z)/(1-ps))
ate = ey1.sum()-ey0.sum()
print("Causal Estimate is " + str(ate))

# correct -> Causal Estimate is 1634.9868359746906<jupyter_output>Causal Estimate is 1634.98683597
{'fraction_non_alphanumeric': 0.13176574977817213, 'fraction_numerical': 0.029724933451641525, 'mean_word_length': 5.498559077809798, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '87267', 'license': 'MIT', 'n_tokens_mistral': 843, 'n_tokens_neox': 775, 'n_words': 200, 'path': 'docs/source/dowhy_lalonde_example.ipynb', 'repo_name': 'TechCityVentures/dowhy', 'size': '2265'}