Announcement

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

  • Dana Fletcher
    started a topic Modification of stored estimates

    Modification of stored estimates

    Dear StataListers,

    Is it possible to recode the _at variable in a stored estimate (see below)? I would like to add 23 units to that variable within the estimate such that they read from 24 to 40.

    This (_at) is a time-centered variable for months in the second period in an interrupted time series that I am trying to overlay using coefplot. The pre-period trendline is plotted from 0 to 40 months, and I want the post-period estimates, which are run using a different variable time-centered such that month 24 is equal to 0, to shift on the plot to start at month 24. I don't want to change it in my regression.

    Code:
    .
    
    margins , at (policyXmontime2=(0(1)16)) post
    
    estimates store aim1_post
    
    estimates table  aim1_post
    
    ---------------------------
        Variable | aim1_post   
    -------------+-------------
             _at |
              1  |  .19411549  
              2  |  .19503899  
              3  |  .19596542  
              4  |  .19689476  
              5  |  .19782702  
              6  |   .1987622  
              7  |  .19970029  
              8  |   .2006413  
              9  |  .20158522  
             10  |  .20253205  
             11  |  .20348179  
             12  |  .20443443  
             13  |  .20538997  
             14  |  .20634842  
             15  |  .20730976  
             16  |    .208274  
             17  |  .20924113  
    ---------------------------
    Thanks!!

  • Dana Fletcher
    replied
    Thanks Daniel! Sorry for my delay in responding to you.

    My problem was that I had 2 elapsed month variables, the first running from 0 to 40, and the second one ranging from 0 to 17. In the second one, non-zero values represented the second half of the study period. I resolved the problem with graphing by recoding the second variable back to 23 to 40 and merging onto the file with the first variable. Once I did that, the graphs overlapped onto the correct months. Not very automated, but it worked.

    Leave a comment:


  • daniel klein
    replied
    Originally posted by Dana Fletcher View Post
    Manipulating the axis doesn't seem to work because it is relying on the numbers 1-17 from the stored estimates table above.
    Unfortunately, you do not provide a reproducible example so I do not really understand the problem. Here is how I would do this

    Code:
    // example dataset
    sysuse auto , clear
    
    // mean-center mpg
    summarize mpg
    local mean = r(mean) // store mean
    generate c_mpg = (mpg-`mean')
    
    // run regression
    regress price i.foreign##c.c_mpg weight
    // ... and margins
    margins foreign , at(c_mpg = (-1 0 1)) post
    
    // create the label
    local at1 : display %9.2f -1+`mean'
    local at2 : display %9.2f `mean'
    local at3 : display %9.2f 1+`mean'
    
    // plot; -coefplot- is from SSC
    coefplot , at xlabel(-1 "`at1'" 0 "`at2'" 1 "`at3'")
    You might want to automate the creation of the xlabel() option. Perhaps there is already some community contributed command that makes this easy; I have not really tried to find one. Anyway, the code above should give you the general idea.

    Best
    Daniel
    Last edited by daniel klein; 11 May 2019, 12:27.

    Leave a comment:


  • Dana Fletcher
    replied
    Daniel,

    Thank you for the suggestions. I have used factor notation. Can you point me to any tutorials on manipulating the e(b) matrix? Manipulating the axis doesn't seem to work because it is relying on the numbers 1-17 from the stored estimates table above.

    Leave a comment:


  • daniel klein
    replied
    You could probably manipulate the respective e(b) matrix but my first intuition would be manipulating the respective axis in the graph.

    More importantly, I am not sure you are getting the correct results in the first place. The name policyXmontime looks like you have manually created an interaction term between policy and montime here. If this is true, margins will probably not produce correct results. When you use interaction terms, use factor variable notation; perhaps something along the lines

    Code:
    ... policy##c.montime
    margins , at(policy = 1 montime = (0(1)16))
    Best
    Daniel

    Leave a comment:

Working...
X