Announcement

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

  • Need help with tricking -coefplot-, thanks to restricted data issues (Ben Jann user written command)

    Dear Statalist:

    I have been using the user-written -coefplot- (authored by Ben Jann). It's great. I have run into an unexpected problem though--I have an analysis using restricted data, and every time I make even the smallest change to the figure, I need to get permission from the staff there to make sure it is isn't violating confidentiality. So if I change colors, or the title, or a note at the bottom, I would need to clear it and go through that bureaucracy. There are good reasons for why I have to do this, but it's been making it very tricky to deal with.

    Officially, I only have to clear the values on the graph; it is considered completely fine for me to clear a table with all of the values I plan to graph, and then graph it at home. I've done this successfully in the past, but -coeplot- runs on stored estimates, and our attempts to trick -coefplot- into reading in the values we want graphed have not been successful. So here are our options, as I see them:
    1) Keep going back to the restricted data office every time we catch a typo in our text
    2) Re-do the coefficient plot from Stata in Excel so that we can mess with it at the home office
    3) Find a way to save the stored estimates, clear the stored estimates with the restricted data office, and then read in the estimates from memory into a file we can load into what we're doing at the home office
    4) Find a way to use the coefficient and standard error and other values that we have already cleared with the data office, put them in a format -coefplot- recognizes, and make it at our home office

    Of these, #4 seems like it would be most preferable but we've also failed at this. Does anyone have any experience that would help us resolve this issue? We love the command, but we're a bit stuck.

    Thank you for your time,
    Jonathan

  • #2
    I'm not following completely what the problem is, but why not just save your betas and CIs as a matrix and then work with it like that?

    Comment


    • #3
      Originally posted by Jared Greathouse View Post
      I'm not following completely what the problem is, but why not just save your betas and CIs as a matrix and then work with it like that?
      That would be fantastic and is more or less what option #4 is that we've been trying, but I have no idea how to do that and then get -coefplot- to recognize it. Are there any examples of someone doing that?

      Comment


      • #4
        Code:
        help estimates##saving

        Comment


        • #5
          Originally posted by Bjarte Aagnes View Post
          Code:
          help estimates##saving
          [Oops]
          Last edited by Jonathan Horowitz; 08 Jan 2023, 12:59. Reason: Misread post; will check out and get back.

          Comment


          • #6
            This is an example from my own work that I think MIGHT be what you're looking for. It isn't 100% analogous, but I'll explain the basics. Consider the following.
            Code:
            clear
            input float(diff_ relative te_ub te_lb)
              .8678263 -19   4.963827  -3.228174
             -.6066594 -18   3.489341 -4.7026596
            -.14151818 -17   3.954482 -4.2375183
             .29513654 -16  4.3911366  -3.800864
            -.06603433 -15   4.029966 -4.1620345
               .448406 -14  4.5444064  -3.647594
             .04231565 -13  4.1383157 -4.0536847
            -.11156338 -12   3.984437 -4.2075634
              .7033208 -11   4.799321 -3.3926795
             -.4564151 -10   3.639585 -4.5524154
             .30846635  -9  4.4044666  -3.787534
             -.5018422  -8   3.594158  -4.597842
             -.2591254  -7   3.836875 -4.3551254
             -.2231608  -6  3.8728395  -4.319161
             .20405325  -5  4.3000536  -3.891947
             .04304723  -4  4.1390476  -4.052953
              .3402093  -3  4.4362097  -3.755791
             .11210825  -2  4.2081084  -3.983892
              -.998571  -1   3.097429  -5.094571
              -6.23134   0 -2.1353397  -10.32734
             -7.417919   1 -3.3219185  -11.51392
            -12.152075   2  -8.056075 -16.248075
            -11.671788   3  -7.575788 -15.767788
            -16.079782   4 -11.983783 -20.175783
             -18.37476   5  -14.27876  -22.47076
             -18.11492   6  -14.01892  -22.21092
             -19.24612   7  -15.15012  -23.34212
            -19.939114   8 -15.843114 -24.035114
             -19.36629   9 -15.270288  -23.46229
              -23.7874  10   -19.6914   -27.8834
            -24.252514  11 -20.156513 -28.348515
            end
            
            cls
            
            mean diff if rel >= 0
            loc pointest: di %6.3g e(b)[1,1]
            
            mat effect = (`pointest')
            
            mean te* if rel >= 0
            loc pointestub: di %6.3g e(b)[1,2]
            loc pointestlb: di %6.3g e(b)[1,1]
            
            mat uncertainty = (`pointestlb' \ `pointestub')
            
            
            coefplot matrix(effect), ci(uncertainty)
            Here, we have diff_ (our treatment effect) and the 95% confidence intervals of this treatment effect (te_lb and te_ub, the upper and lower bounds of our treatment effect, respectively). I begin by taking the average treatment effect in the post intervention period, returning 16.4. I then to the same for my CIs (no doubt, I could do this more efficiently on subsequent versions of my command scul). Anyways, this gives us our confidence interval that we think the effect lies within. After a little rounding, I save these as matricies and make them work with coefplot. Note, that the exact same thing may be done with other commands, you can save your betas and CIS to a matrix and them use them to suit your ends. As Bjarte Aagnes highlights, Stata commands do this by default, to facilitate problems such as this one. Is this about what you desire?

            Comment


            • #7
              This is great--I'm going to try this out and see if it works. I'll get back to this thread if it doesn't.

              Comment


              • #8
                Just to give another less involved example, you can do
                Code:
                clear *
                sysuse auto, clear
                
                
                reg price weight
                
                mat CIs = (r(table)[5,1] \ r(table)[6,1])
                
                mat ests = e(b)[1,1]
                
                
                coefplot matrix(ests), ci(CIs)
                You can also save your matrices to datasets, and make the plot as i do above without showing the command I'm running to obtain my estimates.

                Comment


                • #9
                  Perhaps this example will point you in a useful direction.
                  Code:
                  * within your restricted environment
                  
                  sysuse auto, clear
                  regress price length i.foreign
                  estimates save "/Volumes/FlashDrive/automodel", replace
                  dir "/Volumes/FlashDrive/automodel.*"
                  
                  * outside your restricted environment
                  clear all
                  
                  estimates describe using "/Volumes/FlashDrive/automodel"
                  estimates use "/Volumes/FlashDrive/automodel"
                  estimates replay
                  Code:
                  . * within your restricted environment
                  .
                  . sysuse auto, clear
                  (1978 automobile data)
                  
                  . regress price length i.foreign
                  
                        Source |       SS           df       MS      Number of obs   =        74
                  -------------+----------------------------------   F(2, 71)        =     16.35
                         Model |   200288930         2   100144465   Prob > F        =    0.0000
                      Residual |   434776467        71  6123612.21   R-squared       =    0.3154
                  -------------+----------------------------------   Adj R-squared   =    0.2961
                         Total |   635065396        73  8699525.97   Root MSE        =    2474.6
                  
                  ------------------------------------------------------------------------------
                         price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                        length |   90.21239   15.83368     5.70   0.000     58.64092    121.7839
                               |
                       foreign |
                      Foreign  |   2801.143    766.117     3.66   0.000     1273.549    4328.737
                         _cons |  -11621.35   3124.436    -3.72   0.000     -17851.3   -5391.401
                  ------------------------------------------------------------------------------
                  
                  . estimates save "/Volumes/FlashDrive/automodel", replace
                  file /Volumes/FlashDrive/automodel.ster saved
                  
                  . dir "/Volumes/FlashDrive/automodel.*"
                  
                  -rw-r--r--  1 lisowskiw  staff  19794 Jan  8 15:11 /Volumes/FlashDrive/automodel.ster
                  
                  .
                  . * outside your restricted environment
                  . clear all
                  
                  .
                  . estimates describe using "/Volumes/FlashDrive/automodel"
                  
                    Estimation results saved on 08jan2023 15:11, produced by
                  
                       . regress price length i.foreign
                  
                  . estimates use "/Volumes/FlashDrive/automodel"
                  
                  . estimates replay
                  
                  ------------------------------------------------------------------------------------------------
                  active results
                  ------------------------------------------------------------------------------------------------
                  
                        Source |       SS           df       MS      Number of obs   =        74
                  -------------+----------------------------------   F(2, 71)        =     16.35
                         Model |   200288930         2   100144465   Prob > F        =    0.0000
                      Residual |   434776467        71  6123612.21   R-squared       =    0.3154
                  -------------+----------------------------------   Adj R-squared   =    0.2961
                         Total |   635065396        73  8699525.97   Root MSE        =    2474.6
                  
                  ------------------------------------------------------------------------------
                         price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                  -------------+----------------------------------------------------------------
                        length |   90.21239   15.83368     5.70   0.000     58.64092    121.7839
                               |
                       foreign |
                      Foreign  |   2801.143    766.117     3.66   0.000     1273.549    4328.737
                         _cons |  -11621.35   3124.436    -3.72   0.000     -17851.3   -5391.401
                  ------------------------------------------------------------------------------
                  Note that you want to save your estimates using estimates save, not store your estimates in memory using estimates store. And while I saved them directly to the flash drive, you can obviously save them to disk and then copy them to the flash drive, and similarly copy them from the flash drive to disk when you are outside the restricted environment.
                  Last edited by William Lisowski; 08 Jan 2023, 13:16.

                  Comment

                  Working...
                  X