Announcement

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

  • #16
    Jack Gibson Thanks for all of your help again. The code works perfectly. For continuous variables, I had to remove the (i.) from the logistic regression command for it to work.
    I was think of how to add the the variance table. So I tried this and it didn't work:

    forvalues curreg=2(-1)1 {
    use `maindata', clear // load the data
    tab `var' malperfusion, sdtest matcell(X)
    local chi2val=r(sdtest)
    local sdtestp=r(p)

    .....

    // add in the crosstab results
    svmat X
    gen sdtest=`sdtestval' in 1
    gen sdtest=`sdtestp' in 1

    }

    Comment


    • #17
      Amin Saad It's not working because the tab command doesn't have an option "sdtest", doesn't store any results in r(sdtest), and even if the command ran (which it won't), r(p) would contain the results of the chi square test.

      It looks like what you want to do here is run a -sdtest- command instead. Have a look at the "Stored results" section of the help file for -sdtest- to see what values you can pick out of it. You'll need to remove the tab command, and later commands that refer to things that it produces (the matrix X, r(chi2) and r(p) ) or things that are created based on them, and replace them with things you can get from the -sdtest- command (where relevant).

      Comment


      • #18
        Jack Gibson Thanks Jack for all of your input.This is what I have so far. all of what I need is the variance test p-value, the t-test of equal variance p value and the t-test of unequal variance p -value. Also, I want to the table in sdtest ( Group | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]) Could you please help me fix this ?

        Code:
        tempfile sdtest1
        tempfile ttest1
        tempfile ttest2
        tempfile maindata
        
        save `maindata', replace
        local counter1=0
        
        foreach var in age weight_kg height_cm bmi ef dissect_extent egfr als_present ast_present albumin_admit pt_sec__admit aptt_sec__admit ///
                    wbc_admit hb_admit hct_admit platelets cd_admit bun_admit fibrinogen_admit troponin ph postup_high_wbc postop_high_k ///
                    postop_lactate graft_diameter cirulatory_arrest_time total_pump_time tot_aortic_clamp_time cooling_tem tot_op_time intraop_urine_ouptut ///
                    ebl_ml colloid_ml prbc cell_saver platelets ffp cryo crystalloids los_days po_highest_cr cr_dc maxdiaascendaorta maxidiamarch maxidiamdescendingaorta {
            local sdtest1 "sdtest `var', by(malperfusion)"
            local ttest1 "ttest `var', by(malperfusion)"
            local ttest2 "ttest `var', by(malperfusion) unequal"
        
            forvalues curreg=2(-1)1 {
                use `maindata', clear // load the data
                `sdtest1`curreg'' // run thesdtest
                `ttest1`curreg"
                `ttest2`curreg"
                
                local rownames : rowfullnames MTransposed // extract the row labels
                clear // start a fresh dataset
                svmat MTransposed, names(col) // empty the results into it
            
                // put the row labels into a variable
                gen rowname=""
                local counter=1
                foreach rown of local rownames {
                    replace rowname="`rown'" in `counter'
                    local counter=`counter'+1            
                }
                order rowname
        
                local x=_N+1 // put some empty rows after the results
               set obs `x' // so there are gaps between tables in the final output file
        
                save `reg`curreg'', replace
                append using `reg2'
            }
            // join everything together
            if `counter1'==0 {
                save output, replace    
            }    
            else {
                append using output
                save output, replace
            }
            local counter1=`counter1'+1
        }
        outsheet using ttest1.csv, comma replace
        Last edited by Amin Saad; 20 Aug 2016, 09:41.

        Comment

        Working...
        X