I have a loop in which I run a few t-tests. I would like to post the output of these t-tests using the post command. However, not in every loop is the t-test performed. In some loops there is no data to do a t-test. The problem is that when post hits inputs such as "meanbuy" where there is no local variable defined, the code stops. I have tried adding the command capture to the post command but it didn't work. I also tried to the If {exp} command but it seems it kept going to it even when the if did not hold. Below is the code.
In essence, I would like to run the code even if the t-test has not been run. I do not need though to record the times where a combination of "l" and "v" did not have a t-test output so I don't mind skipping the post line when there is no t-test output. Appreciate your help and hope I was clear in describing my problem.
HTML Code:
levelsof index, local(levels) foreach l of local levels{ di "`l'" sum ret if index == "`l'", meanonly gen mean_ret = r(mean) capture ttest ret = mean_ret if hold_`v' == 1 & check != 0 & index == "`l'" local meanbuy_t = r(t) capture ttest ret = mean_ret if hold_`v' == 0 & check != 0 & index == "`l'" local meansell_t = r(t) capture ttest ret if check != 0 & index == "`l'", by(hold_`v') local meanbuy = r(mu_2) local meansell = r(mu_1) local buysell = meanbuy - meansell local buysell_t = r(t) local sd_b = r(sd_2) local sd_s = r(sd_1) local n_b = r(N_2) local n_s = r(N_1) post `table' ("`l'") ("`v'") (`meanbuy') (`meanbuy_t') (`meansell') (`meansell_t') (`buysell') (`buysell_t') (`sd_b') (`sd_s') (`n_b') (`sd_s')
Comment