Announcement

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

  • Exporting part of output from a loop


    Hi. I am trying to export only part of the output of the flexpaneldid command that is run through a loop on multiple outcome variables. Below is the data, code and full output for one outcome variable. In the output below, I only want to export the last bit "Conditional Diff-in-Diff" table to an excel for each of the outcomes run in the loop. Additionally, the second command in the loop, commented out as "*flexpanel", also generates a graph for every outcome, which I'd like to save. I am unable to figure out how to export only part of the output here, or even the entire output for this command and the graph. Any help will be much appreciated.

    Code:
    
    *Data
    
    clear
    input str50 state byte weeknum float(rate_con_avg7day rate_rec_avg7day rate_dec_avg7day rate_test_avg7day pop_perkm2_2019)
    "Andaman and Nicobar Islands"  3  .00025188917             0             0           0 48.12704
    "Andaman and Nicobar Islands"  4   .0024469234             0             0           0 48.12704
    "Andaman and Nicobar Islands"  5    .002626844   .0007196834             0           0 48.12704
    "Andaman and Nicobar Islands"  6    .002806765     .00259086             0   .05048579 48.12704
    "Andaman and Nicobar Islands"  7    .004713926    .002770781             0   .09640159 48.12704
    "Andaman and Nicobar Islands"  8    .008312343    .003418496             0   .23756747 48.12704
    "Andaman and Nicobar Islands"  9    .008312343    .007916517             0           0 48.12704
    "Andaman and Nicobar Islands" 10    .008312343    .008312343             0           0 48.12704
    "Andaman and Nicobar Islands" 11    .008312343    .008312343             0   1.2649873 48.12704
    "Andaman and Nicobar Islands" 12    .008312343    .008312343             0    1.872976 48.12704
    "Andaman and Nicobar Islands" 13    .008312343    .008312343             0   2.0354803 48.12704
    "Andaman and Nicobar Islands" 14    .008780137    .008312343             0    2.461749 48.12704
    "Andaman and Nicobar Islands" 15    .010759266   .0084562795             0    3.002123 48.12704
    "Andaman and Nicobar Islands" 16       .013638    .009859662             0    3.484779 48.12704
    "Andaman and Nicobar Islands" 17     .02400144    .011982728             0    3.956459 48.12704
    "Andaman and Nicobar Islands" 18     .03573228     .01925153             0     4.38136 48.12704
    "Andaman and Nicobar Islands" 19     .04303706     .03004678             0    4.748615 48.12704
    "Andaman and Nicobar Islands" 20     .05505577     .03983447             0    5.203814 48.12704
    "Andhra Pradesh"               1  5.471253e-07             0             0           0 320.4234
    "Andhra Pradesh"               2  3.009189e-06             0             0           0 320.4234
    "Andhra Pradesh"               3 .000016413758             0             0           0 320.4234
    "Andhra Pradesh"               4  .00014526176  2.462064e-06 2.7356265e-07 .0014375716 320.4234
    "Andhra Pradesh"               5   .0005900746 .000011763193  6.839066e-06 .0017436882 320.4234
    "Andhra Pradesh"               6   .0009243682  .00003419533 .000019970073   .02332368 320.4234
    "Andhra Pradesh"               7   .0014745026   .0001917674  .00004240221   .07079199 320.4234
    "Andhra Pradesh"               8    .002392852   .0005214104  .00005991022   .15572937 320.4234
    "Andhra Pradesh"               9    .003275092   .0012017606  .00006784353    .2542428 320.4234
    "Andhra Pradesh"              10   .0040120697   .0020385887  .00008836073    .3673837 320.4234
    "Andhra Pradesh"              11    .004784063    .003031621  .00009930324    .4304929 320.4234
    "Andhra Pradesh"              12    .005759861    .003819208  .00010997218    .6190895 320.4234
    "Andhra Pradesh"              13    .007340232   .0046437257  .00012638593     .753984 320.4234
    "Andhra Pradesh"              14     .00960916    .005391099   .0001471767     .922762 320.4234
    "Andhra Pradesh"              15    .013052767    .006761648   .0001690617   1.1162204 320.4234
    "Andhra Pradesh"              16     .01895543    .008865618   .0002319811   1.3809762 320.4234
    "Arunachal Pradesh"            4  .00001899696             0             0           0 17.95971
    "Arunachal Pradesh"            5  .00006648936             0             0           0 17.95971
    "Arunachal Pradesh"            6  .00006648936  .00002849544             0 .0080642095 17.95971
    "Arunachal Pradesh"            7  .00006648936  .00006648936             0    .0218845 17.95971
    "Arunachal Pradesh"            8  .00006648936  .00006648936             0   .03649316 17.95971
    "Arunachal Pradesh"            9  .00006648936  .00006648936             0    .0587576 17.95971
    end
    
    
    
    
    *Code
    local ylist rate_con_avg7day rate_rec_avg7day rate_dec_avg7day
    
    foreach y of local ylist { 
        
        use "${output}/flexpanel.dta", clear
        
        *running the preprocessing data
        flexpaneldid_preprocessing, id(state) treatment(stepone) time(weeknum) ///
        matchvars(pop_perkm2_2019 rate_test_avg7day) matchtimerel(-1) ///
        prepdataset(flexpaneldid_preprocessing1) replace
        
        use "${output}/flexpanel.dta", clear
        
        *flexpanel 
        flexpaneldid `y', id(state) treatment(stepone) time(weeknum)  ///
        prepdataset(flexpaneldid_preprocessing1.dta) statmatching(con(pop_perkm2_2019 rate_test_avg7day)) ///
        outcometimerelstart(1) outcomedev(-1) test  
    
    }
    
    
    
    *Output
    
    
    ********************************************************************************
    ************************* flexpaneldid - Matching Summary **********************
    ********************************************************************************
    
                   |          NT           T
    ---------------+------------------------------
    All            |          19          15
    Matched sample |          11          15
    
    
    
    ********************************************************************************
    ************************* ps-test **********************************************
    ********************************************************************************
    
    
    ------------------------------------------------------------------------------
                            |       Mean               |     t-test    |  V(T)/
    Variable                | Treated Control    %bias |    t    p>|t| |  V(C)
    ------------------------+--------------------------+---------------+----------
    pop_perkm2_2019         | 1405.1     1068     11.2 |   0.31  0.762 |  1.73
    rate_test_avg7day       | .52876   .44195      9.7 |   0.26  0.793 |  1.47
    outcome_dev             | .00034   .00024     22.4 |   0.61  0.545 |  2.10
    ------------------------------------------------------------------------------
    * if variance ratio outside [0.34; 2.98]
    
    ----------------------------------------------------------------------
    Ps R2   LR chi2   p>chi2   MeanBias   MedBias      B       R     %Var 
    ----------------------------------------------------------------------
    0.011      0.44    0.932     14.4      11.2      23.3    1.82       0
    ----------------------------------------------------------------------
    * if B>25%, R outside [0.5; 2]
    
    
    ********************************************************************************
    ************************* KS-Test **********************************************
    ********************************************************************************
    
    ksmirnov pop_perkm2_2019 , by(treated)
    
    Two-sample Kolmogorov–Smirnov test for equality of distribution functions
    
    Smaller group             D     p-value  Corrected
    --------------------------------------------------
    0                    0.2000       0.549
    1                   -0.2667       0.344
    Combined K-S         0.2667       0.660      0.551
    
    Note: Ties exist in combined dataset;
          there are 26 unique values out of 30 observations.
    ksmirnov rate_test_avg7day , by(treated)
    
    Two-sample Kolmogorov–Smirnov test for equality of distribution functions
    
    Smaller group             D     p-value  Corrected
    --------------------------------------------------
    0                    0.1333       0.766
    1                    0.0000       1.000
    Combined K-S         0.1333       0.999      0.999
    
    Note: Ties exist in combined dataset;
          there are 27 unique values out of 30 observations.
    ksmirnov outcome_dev , by(treated)
    
    Two-sample Kolmogorov–Smirnov test for equality of distribution functions
    
    Smaller group             D     p-value  Corrected
    --------------------------------------------------
    0                    0.1333       0.766
    1                   -0.0667       0.936
    Combined K-S         0.1333       0.999      0.999
    
    Note: Ties exist in combined dataset;
          there are 21 unique values out of 30 observations.
    
    
    ********************************************************************************
    ************************* Conditional Diff-in-Diff *****************************
    ********************************************************************************
    
    Average treatment effect for the treated
    Estimator       : Nearest neighbor          No. of treated obs       =        15
    Distance metric : Statistical DF            No. of unique controls   =        11
                                                Mean no. of matches      =         1
    --------------------------------------------------------------------------------
    Outcome     |       mean Diff      |   DiD*   |AI robust |     z        P>|z|
                |  treated  | controls |          |   S.E.   |          |
    ------------+-----------+----------+----------+----------+----------+-----------
    rate_dec~y  |  0.0003   | 0.0001   |  0.0002  |  0.0007  |  0.2424  |  0.8120
    --------------------------------------------------------------------------------
    * Consistent bias-corrected estimator as proposed in Abadie & Imbens (2006,2011).
    
    
    . 
    
    }
Working...
X