Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Adding kwallis p value to multiple graphs


From   Colin Campbell <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Adding kwallis p value to multiple graphs
Date   Mon, 24 Sep 2012 02:03:07 -0700 (PDT)

Dear statalist,

I am drawing several graphs within a loop and wish to insert a p value from kwallis into each one in the -note- option.
How can this be achieved without sacrificing the loop? My attempt at this is shown below.
I think the problem is in naming the macro(s) that hold(s) the individual p results.
The new_diag variable take values of 0 or 1 so each graph is drawn twice and needs a different p value.

Any assistance appreciated to face this challenge with fortitude.

Colin

levelsof new_diag, local(levels)
foreach l of local levels {

    foreach var of varlist sex agegroup risk_group origen_redux education_bin {

        kwallis risk_score if new_diag ==`l', by(`var')
        local `l'_`var' = chi2tail(r(df), r(chi2))
    }
twoway kdensity risk_score if new_diag ==`l' & sex ==1 || ///
    (kdensity risk_score if new_diag ==`l' & sex ==2), ///
    title("Sexual risk score by sex", position(12)) ///
    ytitle("Density") ///
    xtitle("Risk score", size(small)) ///
    legend(cols(1) label(1 "Male") label(2 "Female") ring(0) position(10) size(small)) ///
    note("`l'_`var'", ring(0) position(6)) ///
    saving(`l'_1, replace)  scheme(tufte)

twoway kdensity risk_score if new_diag ==`l' & agegroup ==1 || ///
    (kdensity risk_score if new_diag ==`l' & agegroup ==2) || ///
    (kdensity risk_score if new_diag ==`l' & agegroup ==3) || ///
    (kdensity risk_score if new_diag ==`l' & agegroup ==4), ///
    title("Sexual risk score by age group", position(12)) ///
    ytitle("Density") ///
    xtitle("Risk score", size(small)) ///
    legend(cols(1) label(1 "<30") label(2 "30-39") label(3 "40-49") label(4 "50+") ring(0) position(10) size(small)) ///
    note("`p'", ring(0) position(2)) ///
    saving(`l'_2, replace)  scheme(tufte)

}


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index