Announcement

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

  • #16
    Ask the counterfactual. Given the equation

    $$(e^{x}-1)\times 100 = 50$$

    what is the corresponding value of \(x\) that satisfies the equation? My rusty high-school math skills tell me that I can resolve this as:

    $$e^{x}= 1.5$$

    and to get \(x\), I need to take the natural logarithm of both sides:

    $$x = ln(1.5)\approx 0.405$$

    the similar values for 0 and 100 are 0 [or ln(1)] and ln(2).


    Code:
    use "https://www.stata-press.com/data/r17/nlsw88.dta", clear
    
    reg wage never_married
    est store c1
    mat pct= e(b)
    forval i=1/`=colsof(pct)'{
        mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
    }
    estadd mat pct= pct: c1
    
    
    
    reg wage never_married c.age##c.tenure
    est store c2
    mat pct= e(b)
    forval i=1/`=colsof(pct)'{
        mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
    }
    estadd mat pct= pct: c2
    
    
    reg wage never_married c.tenure
    est store c3
    mat pct= e(b)
    forval i=1/`=colsof(pct)'{
        mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
    }
    estadd mat pct= pct: c3
    
    reg wage never_married c.grade
    est store c4
    mat pct= e(b)
    forval i=1/`=colsof(pct)'{
        mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
    }
    estadd mat pct= pct: c4
    
    set scheme s1color
    gen newvar1= "`=uchar(28)'             %"
    gen newvar2= "`=uchar(28)'           %"
    
    coefplot (c1, label(Wage 1) pstyle(p1)) ///
    (c2, label(Wage 2) pstyle(p2)) ///
    (c3, label(Wage 3) pstyle(p3)) ///
    (c4, label(Wage 4) pstyle(p4)) ///
    , aux(pct) ci(95) vertical recast(bar) keep(never_married) barwidth(0.15) fcolor(*.5) ciopts(recast(rcap)) ///
    citop xlabel("") xtitle("") ylabel(, format(%4.2f) labsize(small)) ytitle("") ///
    title("") graphregion(color(white)) yline(0, lcolor(black) lpattern(dashed)) legend(cols(1) pos(6)) ///
    addplot((scatter @b @at, ms(i) mlabel(@aux1) mlabformat(%4.3f) mlabpos(2) mlabcolor(black)) ///
    (scatter @b @at if int(@aux)>=100, ms(none) mlabel(newvar1) mlabpos(2)  mlabcolor(black)) ///
    (scatter @b @at if int(@aux)<100, ms(none) mlabel(newvar2) mlabpos(2) mlabcolor(black))) ///
    saving(gr2, replace) title(Wanted) ///
    ylab(`=ln(1)' "0" `=ln(1.5)' "50" `=ln(2)' "100")
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	24.7 KB
ID:	1732612


    Comment


    • #17
      That's brilliant, thank you very much. However, is there a way to display a non-distorted y-axis? The distances are currently not even. Can this be fixed? Thanks again!

      Comment


      • #18
        The transformation is not linear, so the axis values do not increase linearly. It seems that you want to plot the transformed coefficients. The following uses erepost from SSC to repost the coefficients' and variances matrices.

        Code:
        use "https://www.stata-press.com/data/r17/nlsw88.dta", clear
        
        reg wage never_married
        mat pct= e(b)
        mat var=e(V)
        forval i=1/`=colsof(pct)'{
            mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
            mat var[`i', `i']= ((exp(sqrt(var[`i', `i']))-1)*100)^2
        }
        erepost b= pct, rename
        erepost V=var, rename
        est store c1
        
        
        reg wage never_married c.age##c.tenure
        mat pct= e(b)
        mat var=e(V)
        forval i=1/`=colsof(pct)'{
            mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
            mat var[`i', `i']= ((exp(sqrt(var[`i', `i']))-1)*100)^2
        }
        erepost b= pct, rename
        erepost V=var, rename
        est store c2
        
        
        reg wage never_married c.tenure
        mat pct= e(b)
        mat var=e(V)
        forval i=1/`=colsof(pct)'{
            mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
            mat var[`i', `i']= ((exp(sqrt(var[`i', `i']))-1)*100)^2
        }
        erepost b= pct, rename
        erepost V=var, rename
        est store c3
        
        
        reg wage never_married c.grade
        mat pct= e(b)
        mat var=e(V)
        forval i=1/`=colsof(pct)'{
            mat pct[1, `i']= (exp(pct[1, `i'])-1)*100
            mat var[`i', `i']= ((exp(sqrt(var[`i', `i']))-1)*100)^2
        }
        erepost b= pct, rename
        erepost V=var, rename
        est store c4 
        
        set scheme s1color
        gen newvar1= "`=uchar(28)'           %"
        gen newvar2= "`=uchar(28)'         %"
        
        coefplot (c1, label(Wage 1) pstyle(p1)) ///
        (c2, label(Wage 2) pstyle(p2)) ///
        (c3, label(Wage 3) pstyle(p3)) ///
        (c4, label(Wage 4) pstyle(p4)) ///
        , aux(pct) ci(95) vertical recast(bar) keep(never_married) barwidth(0.15) fcolor(*.5) ciopts(recast(rcap)) ///
        citop xlabel("") xtitle("") ylabel(, format(%4.0f) labsize(small)) ytitle("") ///
        title("") graphregion(color(white)) yline(0, lcolor(black) lpattern(dashed)) legend(cols(1) pos(6)) ///
        addplot((scatter @b @at, ms(i) mlabel(@b) mlabformat(%4.2f) mlabpos(2) mlabcolor(black)) ///
        (scatter @b @at if int(@b)>=100, ms(none) mlabel(newvar1) mlabpos(2)  mlabcolor(black)) ///
        (scatter @b @at if int(@b)<100, ms(none) mlabel(newvar2) mlabpos(2) mlabcolor(black))) ///
        saving(gr2, replace) title(Wanted)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.3 KB
ID:	1732902

        Comment

        Working...
        X