Announcement

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

  • Weight markers in coefplot by created matrix

    I am trying to weight markers in coefplot via a matrix of means (because they are proportions they vary from 0-1). Below i generate weights using mean, and save them (Rprop_p, Rprop_p, Rprop_p, Rprop_n), but the coefplot does NOT use them. This coefplot code outputs the attached figure (the one with 2 marker colors).

    Code:
        reghdfe wheat_yield c.hyv_prop#i.st66code $COV  if POSEFFECT==1, ///
            absorb(distcode i.st66code##i.year) vce(cluster distcode)
            estimates store W_p
        reghdfe wheat_yield c.hyv_prop#i.st66code $COV  if POSEFFECT==0, ///
            absorb(distcode i.st66code##i.year) vce(cluster distcode)
            estimates store W_n
        reghdfe rice_yield c.hyv_prop#i.st66code $COV if POSEFFECT==1, ///
            absorb(distcode i.st66code##i.year) vce(cluster distcode)
            estimates store R_p
        reghdfe rice_yield c.hyv_prop#i.st66code $COV if POSEFFECT==0, ///
            absorb(distcode i.st66code##i.year) vce(cluster distcode)
            estimates store R_n        
    
    * Weights:
        mean proprice if year<1970 & POSEFFECT==1, over(st66)
            mat Rprop_p = e(b)
        mean proprice if year<1970 & POSEFFECT==0, over(st66)
            mat Rprop_p = e(b)
        mean propwheat if year<1970 & POSEFFECT==1, over(st66)
            mat Rprop_p = e(b)
        mean propwheat if year<1970 & POSEFFECT==0, over(st66)
            mat Wprop_n = e(b)
            
        coefplot (R_p, label("Responsive") mcolor(green) ciopts(lcolor(green)))  ///
                (R_n, label("Unresponsive")), bylabel(Rice) ||  ///
                (W_p, label("Responsive") mcolor(green) ciopts(lcolor(green))) ////
                (W_n, label("Unresponsive")), bylabel(Wheat) ///
            drop(_cons $COV) xline(0) byopts(xrescale)
    The problem is, I can't figure out how to feed my weights into my coefplot. I need to put them within each of the 4 separate sets of markers, but adding weight(Rprop_p) after R_p, as below doesn't work -- no plot is created, I instead get the error type mismatch.

    Code:
        
        coefplot (R_p, weight(Rprop_p) Label("Responsive") mcolor(green) ciopts(lcolor(green)))  ///
                (R_n, label("Unresponsive")), bylabel(Rice) ||  ///
                (W_p, label("Responsive") mcolor(green) ciopts(lcolor(green))) ////
                (W_n, label("Unresponsive")), bylabel(Wheat) ///
            drop(_cons $COV) xline(0) byopts(xrescale)
    Following this help here I tried using aux as below, but that outputs a mostly empty graphic (very odd) with the error/note (R_p: e(Rprop_p) not found). I suspect the problem there is that aux() only recognizes e() objects, but since each of my weights is originally called e(b) I can't use e(b) to call them.

    Code:
        coefplot (R_p, aux(Rprop_p) weight(@aux1) label("Responsive") mcolor(green) ciopts(lcolor(green)))  ///
                (R_n, label("Unresponsive")), bylabel(Rice) ||  ///
                (W_p, label("Responsive") mcolor(green) ciopts(lcolor(green))) ////
                (W_n, label("Unresponsive")), bylabel(Wheat) ///
            drop(_cons $COV) xline(0) byopts(xrescale)
    Last note -- I would be happier, actually, to generate only 2 sets of coefficients and 2 sets of weights as with the code below, but then I need to be able to pick and choose which markers are which color by marker label, and I couldn't figure out how to do that. That graphic (all dark blue markers) is also attached. In general, estimating an equation twice by sub-sample will obviously NOT give the same coefficients, but in this particular case (where the markers are state-specific and the subset is for a group of states) the coefficients are very close to identical... though not actually identical because of the shared coefficients in $COV. So bonus if somebody can help me to figure out how to weight this coefplot below, AND how to color by marker such that markers associated with certain values of st66code are certain colors, e.g. 1.st66code#hyv_prop (Bihar's beta) is green but 2.st66code#hyv_prop (Gujarat's beta) is dark red.

    Code:
        reghdfe wheat_yield c.hyv_prop#i.st66code $COV , ///
            absorb(distcode i.st66code##i.year) vce(cluster distcode)
            estimates store W
        eststo: reghdfe rice_yield c.hyv_prop#i.st66code $COV , ///
            absorb(distcode i.st66code##i.year) vce(cluster distcode)
            estimates store R
    
        mean proprice if year<1970 , over(st66)
            mat Rprop = e(b)
        mean propwheat if year<1970 , over(st66)
            mat Wprop = e(b)
    
        coefplot (R), bylabel(Rice) || (W), bylabel(Wheat) ///
            drop(_cons $COV) xline(0) byopts(xrescale)
    LATER EDIT: As I read back over the last bit of my question, I realized that oddly, Gujarat's coefficients are NOT appearing in the coefplot where I plot markers for each subsets of states (green marker states vs. red marker states) -- And the Andhra Pradesh coefficient is not being produced in EITHER graphic! The regression matrix output e(b) all contain those AP and Gujarat coefficients, and I'm realizing that coefplot is dropping the first coefficient, the one that the matrix output lists with a b -- 1b.st66code#c.hyv_prop for the whole sample or for the POSEFFECT==1 sample, and 1b.st66code#c.hyv_prop for the POSEFFECT==0 sample. So in addition to the weight and the marker color question above, I would also like to know how I can keep coefplot from dropping the first coefficient from the regression e(b) matrix! I really apologize for the multi-layered nature of this post.
    Attached Files
    Last edited by Leah Bevis; 27 Mar 2024, 10:53.

  • #2
    Can you add a data example that reproduces the issues that you raise?

    Comment

    Working...
    X