Hi all,
As sensitivity analysis for my project I want to estimate e-values for my final statistical models (both in complete case and imputed dataset) for every regression models I have run – and there are several. The script works fine when I run in separate linear regressions using margins to obtain the SE to use to calculate the pooled standard deviation (sdp), use esizeregi to get the SMD and input that into the evalue command. However, because I have several models I have tried to put these steps into a loop. I have tried to debug this and it says that I do not have n2 (is missing or 0) but this is not true. I do not receive any error message but then the temporary dataset is empty – thus the loop is not working properly.
My script is:
I am using STATA v17 for Windows.
Also, I have more of a statistical question that a STATA question too. I have used this to obtain evalue for SMD
as guidance even though sdy does not work anymore (at least for me) and it requires sdp which I obtain as by guidance in the stata evalue help file. I am asked to inpute n1 and n2 for the two groups of the exposure/independent variable however it does not specify what to do in case of missing data. Should I input the numbers of the groups as by completeness in the regression model not the full sample? Do you know if these commands will work too in my imputed datasets?
Sorry if I am asking something that is very obvious, but I cannot find an easy answer anywhere. Any help would be really appreciated! Thanks!!
As sensitivity analysis for my project I want to estimate e-values for my final statistical models (both in complete case and imputed dataset) for every regression models I have run – and there are several. The script works fine when I run in separate linear regressions using margins to obtain the SE to use to calculate the pooled standard deviation (sdp), use esizeregi to get the SMD and input that into the evalue command. However, because I have several models I have tried to put these steps into a loop. I have tried to debug this and it says that I do not have n2 (is missing or 0) but this is not true. I do not receive any error message but then the temporary dataset is empty – thus the loop is not working properly.
My script is:
Code:
* Always use this dataset from now on for the analyses use "dataset.dta", clear * Define the outcomes and independent variables local outcomes "outcome1 outcome2 outcome3 outcome4 outcome5 outcome6 outcome7" local indep_vars "exp cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10 cov11 cov12 cov13 cov14 cov15 cov16" * Initialize an empty dataset to store the results tempfile results_file capture postclose results postfile results str32 outcome float(beta pooled_sd n1 n2 smd se_smd evalue) using `results_file' * Loop through each outcome foreach outcome in `outcomes' { display "Processing outcome: `outcome'" * Drop residuals variable if it exists to prevent conflicts capture drop residuals * Run regression for the outcome regress `outcome' `indep_vars' if model7out == 1 if _rc { display as error "Regression failed for outcome: `outcome'" continue } * Store the coefficient for `anydeb16` local beta = _b[anydeb16] * Calculate pooled SD from residuals predict residuals, residuals if _rc { display as error "Predict failed for outcome: `outcome'" continue } su residuals local pooled_sd = r(sd) * Validate pooled_sd if missing(`pooled_sd') | `pooled_sd' == 0 { display as error "Pooled SD is missing or zero for outcome: `outcome'" continue } * Get the number of observations in each group tabulate anydeb16 if model7out == 1 matrix N = r(N) local n1 = N[1,1] local n2 = N[2,1] * Validate group sizes if missing(`n1') | missing(`n2') | `n1' == 0 | `n2' == 0 { display as error "Group sizes are missing or zero for outcome: `outcome'" continue } * Compute SMD esizeregi `beta', sdp(`pooled_sd') n1(`n1') n2(`n2') if _rc { display as error "esizeregi failed for outcome: `outcome'" continue } local smd = r(smd) local se_smd = r(se) * Compute E-value evalue smd `d', se(`se') true(0) fig if _rc { display as error "evalue failed for outcome: `outcome'" continue } local evalue = r(evalue) * Post the results post results ("`outcome'") (`beta') (`pooled_sd') (`n1') (`n2') (`d') (`se') (`evalue') * Clean up drop residuals } * Close the postfile postclose results * Use the results dataset and list use `results_file', clear list
Also, I have more of a statistical question that a STATA question too. I have used this to obtain evalue for SMD
HTML Code:
https://journals.sagepub.com/doi/full/10.1177/1536867X20909696#bibr25-1536867X20909696
Sorry if I am asking something that is very obvious, but I cannot find an easy answer anywhere. Any help would be really appreciated! Thanks!!
Comment