Announcement

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

  • Storing and graphing the lincom estimates (inside the loop)

    After running the regression, I did the lincom, and then stored the estimates (with local as well as esttad scalar commands). After that I try to plot these estimates by using coefplot. I am unable to. Can someone please help? Also, if possible, I'd like to do the graphs inside the loop.

    Is there another way of graphing lincom estimates other than using coefplot? Here is my command:

    loc interact_controls "c.subj_male#c.conf_male c.subj_male#c.conf_female c.subj_female#c.conf_male c.subj_female#c.conf_female"

    foreach DV of varlist ped_help eyecontact ped_comfort {
    reg `DV' `interact_controls', noc cluster(CLUSTER)
    * Male subject (DVs) female confederate more/less by (coefficient)
    lincom c.subj_male#c.conf_female - c.subj_male#c.conf_male
    loc coef_msubj_conf = r(estimate)
    loc se_msubj_conf = r(se)
    * Female subject (DVs) female confederates more/less by (coefficient)
    lincom c.subj_female#c.conf_female - c.subj_female#c.conf_male
    loc coef_fsubj_conf = r(estimate)
    loc se_fsubj_conf = r(se)
    * Difference of the two lincom estimates
    lincom coef_msubj_conf - coef_fsubj_conf
    loc coef_diff = r(estimate)
    loc se_diff = r(se)
    * Plot lincom coefficient estimates and standard errors
    *coefplot coef_msubj_conf coef_fsubj_conf coef_diff, drop(_cons) yline(0) vertical bycoefs byopts(yrescale)
    }

  • #2
    coefplot is from SSC (FAQ Advice #12). I would recommend using margins with the -post- option and estimates store in place of lincom and then graphing the stored results with coefplot. For any specific code suggestions, review FAQ Advice #12 on how to present a data example using the dataex command. Alternatively, you can use one of Stata's datasets to create a reproducible example.

    Comment


    • #3
      I'm not sure about the exact coefplot specification since I have no data to test it, but xlincom (from SSC) can help here.
      Code:
      ssc install xlincom
      
      foreach DV of varlist ped_help eyecontact ped_comfort {
          reg `DV' `interact_controls', noc cluster(CLUSTER)
      
          xlincom (msubj_conf = c.subj_male#c.conf_female - c.subj_male#c.conf_male) ///
              (fsubj_conf = c.subj_female#c.conf_female - c.subj_female#c.conf_male) ///
              (diff = (c.subj_male#c.conf_female - c.subj_male#c.conf_male) - (c.subj_male#c.conf_female - c.subj_male#c.conf_male)), post
          coefplot
      }

      Comment


      • #4
        Thank you so much Wouter Wakker! The code works perfectly. I was also wondering if you would know a way of to store the standard errors from the lincom estimates (I know "loc" command, which doesn't help with plotting), and a way to plot the standard errors in the same graph and also to include coefficient intervals, if that makes sense.

        Comment


        • #5
          I don't understand why you would want to plot both standard errors and confidence intervals. I don't use coefplot often so I cannot give you advice on that, but help coefplot is the first source of information. If all else fails you might have to revert to twoway scatter combined with twoway rcap for more flexilibility.

          With regards to accessing standard errors, xlincom stores that information in r(table), type mat list r(table) to see the contents. You can store r(table) in a matrix and access these results in a matrix-like fashion. The _se[myvar] syntax also works after xlincom, post.

          Comment

          Working...
          X