Announcement

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

  • LPM crosstab prediction accuracy

    Hello everyone,

    I have estimated an LPM regression, now I would like to display the prediction probability. Since I want to use nestreg to show how my model changes after adding each control variable, I would like to show this in a cross tabulation. There I would like to show the number of true positives, false positives, true negatives and false negatives for each added regressor. I have made a start here, but I don't know if my approach is wrong or too complex. I would like to export these tables to Excel. . I would also like to graphically display the accuracy of the comparison after each added regressor, i.e. how the sensitivity, specificity... changes after each model compared to the previous one.


    quietly: nestreg ,store(m): regress Übergewichtig Jahreseinkommen `y', cluster(idpers)

    local th 0.5
    local nmodel = 13


    putexcel set "...Vohersagenauigkeit", replace sheet("valid1")

    forvalues i = 1/`nmodel' {
    estimates restore m`i'
    predict Yhat`i'

    putexcel set "...Vohersagenauigkeit", modify sheet("Valid`i'", replace)
    preserve
    keep if !missing(Yhat`i')

    gen valid`i' = .
    replace valid`i' = 1 if Übergewichtig == 1 & Yhat`i' > `th'
    replace valid`i' = 2 if Übergewichtig == 0 & Yhat`i' > `th'
    replace valid`i' = 3 if Übergewichtig == 0 & Yhat`i' <= `th'
    replace valid`i' = 4 if Übergewichtig == 1 & Yhat`i' <= `th'
    label variable valid`i' "Vohersagegenauigkeit"
    label define valid_`i' 1 "Richtig Positiv" 2 "Falsch Positiv" 3 "Richtig Negativ" 4 "Falsch Negativ"
    label values valid`i' valid_`i'

    tab valid`i', gen(v`i'_)



    foreach dummy of varlist v`i'_* {

    local z = `z' + 1
    replace `dummy' = . if `dummy' ==0
    tabstat `dummy', stats(n) /// metrics
    format(%9.2f) /// option for rounding
    save

    matrix res = r(StatTotal)' // export results as transposed matrix for
    quietly: putexcel A`z'=matrix(res), rownames nformat(number_d2)

    * use value label as variable description
    local lbl: variable label `dummy'
    local lbl: subinstr local lbl "`v'==" ""
    local lbl = strproper("`lbl'")
    quietly: putexcel A`z' = "`lbl'"

    }

    restore
    putexcel close
    }


    I hope you can understand my problem, thank you.

Working...
X