Announcement

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

  • Automating Variable Transformations in a Loop for MAE Computation

    Hi Everyone,

    I'm working on computing a 95% confidence interval for the mean absolute error (MAE) while adjusting for optimism in a model.
    However, I'm encountering an issue with the mfp command in my loop. Specifically, the transformed variables generated by mfp
    are not available in the original dataset within the loop. Manually transforming these variables for each iteration isn't practical.

    Does anyone know how I can make these transformations available automatically without manually transforming them every time?

    Here is my code -

    use sub_data,clear

    set seed 1994

    pwcorr aw vw at vt aa va aprec vprec

    xi: mfp, select(0.1): regress age_fin var1 var2 var3 var4 var5 var6 var7 var8

    predict age_hat, xb

    gen abs_error = abs(age_fin - age_hat)

    summarize abs_error, meanonly

    global mae = r(mean)

    di "Mean Absolute Error: " $mae

    global r2 = e(r2)

    di $r2


    matrix results_img_lvl_be = J(5,2,.)
    set seed 1994

    forvalues i=1/200 {

    use "sub_data", clear

    bsample

    append using "sub_data", gen(original)


    xi: mfp, select(0.1): regress age_fin var1 var2 var3 var4 var5 var6 var7 var8 if original == 0

    predict lp, xb


    gen abs_error = abs(age_fin - lp)

    summarize abs_error if original == 0, meanonly


    matrix results_img_lvl_be[`i',1] = r(mean)

    summarize abs_error if original == 1, meanonly

    matrix results_img_lvl_be[`i',2] = r(mean)


    }


  • #2
    Cross-posted at https://stats.stackexchange.com/ques...ae-computation

    Please note our request that you tell us about cross-posting. https://www.statalist.org/forums/help#crossposting

    People interested in posting an answer don't want to duplicate others' effort. People interested in seeing an answer should want to see one anywhere it is posted.

    I've seen opinions posted that cross-posting at all is offensive to people on any one site. I don't agree with that at all, but warn that the attitude exists too.

    In this case, sorry, I have no idea to help. I've never used mfp and so stop there.

    Your post on CV seems likely to be closed as off-topic, but that's for that community.

    Comment


    • #3
      Hey there!

      I apologize for the cross-posting. I’ve removed the post from the other site. Thank you for your understanding.

      Comment

      Working...
      X