Hello everyone,
I'm trying to make some logistic regressions comparing a set of dichotomic (1 and 0) variables through a loop, retrieving the names of those variables as well as betas and p values. I want the latter to use in forthcoming analysis so I'm posting them to a .dta file. The code seems to work fine, except that it doesn't retrieve correctly the p values, posting a "." instead.
I believe the error is due to the fact that some of the regressions don't seem to actually have betas and p values (the regression table looks empty for those).
I'm relatively new to stata so any help on fixing this would be really appreciated.
Sample code here:
Thanks in advance!
I'm trying to make some logistic regressions comparing a set of dichotomic (1 and 0) variables through a loop, retrieving the names of those variables as well as betas and p values. I want the latter to use in forthcoming analysis so I'm posting them to a .dta file. The code seems to work fine, except that it doesn't retrieve correctly the p values, posting a "." instead.
I believe the error is due to the fact that some of the regressions don't seem to actually have betas and p values (the regression table looks empty for those).
I'm relatively new to stata so any help on fixing this would be really appreciated.
Sample code here:
Code:
clear
postutil clear
tempname File
use "C:\Users\User_1\Desktop\Database.dta"
postfile `File' str10 V_IND str10 V_DEP Beta PValue using C:\Users\User_1\Desktop\Results.dta, replace
local VARS "var1 var2 ... var41" //Here, instead of the "..." I wrote the full 41 variables
local NUM : word count `VARS'
forval i=1/`NUM'{
local iv `: word `i' of `VARS''
local z = `i'+1
forval j=`z'/`NUM'{
local dv `: word `j' of `VARS''
logistic `iv' `dv'
local t = _b[`dv']/_se[`dv']
post `File' (`"`iv'"') (`"`dv'"') (_b[`dv']) (2*ttail(e(df_r),abs(`t')))
}
}
postclose `File'
clear
use C:\Users\User_1\Desktop\Results.dta
Thanks in advance!

Comment