Hi All,
Have been using STATA for only 6 months now, first time posting.
Am completing a piece of analysis work that involves using GLM.
My original code is:
putexcel set "directory", sheet("name")modify
putexcel A1=("Variable") B1 = ("b") C1=("ll") D1=("ul") E1=("P")
loc row = 2
foreach x of varlist [indep var] {
glm [dep var] `x',family(gaussian) link(identity) vce(robust)
putexcel A`row' = ("`x'") B`row' = (_b[`x']) C`row' = (_b[`x']-1.96*_se[`x']) D`row' = (_b[`x']+1.96*_se[`x']) E`row' = (2*ttail(e(df), abs(_b[`x']/_se[`x']))) F`row' = matrix(e(N))
loc row = `row' + 1
}
I now want to run the analysis, sorting first my [indep var] by ethnicity. I have created a new variable "ChineseOnly" and coded it as Chinese 0 and Others 1. My new code is:
Sort Chinese Only
putexcel set "directory", sheet("name")modify
putexcel A1=("Variable") B1 = ("b") C1=("ll") D1=("ul") E1=("P")
loc row = 2
foreach x of varlist [indep var] {
by ChineseOnly: glm [dep var] `x',family(gaussian) link(identity) vce(robust)
putexcel A`row' = ("`x'") B`row' = (_b[`x']) C`row' = (_b[`x']-1.96*_se[`x']) D`row' = (_b[`x']+1.96*_se[`x']) E`row' = (2*ttail(e(df), abs(_b[`x']/_se[`x']))) F`row' = matrix(e(N))
loc row = `row' + 1
}
The analysis is running fine, however the put excel is not. STATA is only exporting the last set of GLM results. So for example if I have one indep variable, there will be two sets of GLM results 1.indep variable + Chinese (coded as 0) and 2. indep variable + Others (coded as 1), however STATA is only exporting for the last set of GLM results produced in this case being 2.indep variable + Others.
I can not work out how to alter the put excel so that it exports all sets of results for the macro.
Any advice would be greatly appreciated as I need to run the analysis on a large list of dep variables.
thanks!
Mel
Have been using STATA for only 6 months now, first time posting.
Am completing a piece of analysis work that involves using GLM.
My original code is:
putexcel set "directory", sheet("name")modify
putexcel A1=("Variable") B1 = ("b") C1=("ll") D1=("ul") E1=("P")
loc row = 2
foreach x of varlist [indep var] {
glm [dep var] `x',family(gaussian) link(identity) vce(robust)
putexcel A`row' = ("`x'") B`row' = (_b[`x']) C`row' = (_b[`x']-1.96*_se[`x']) D`row' = (_b[`x']+1.96*_se[`x']) E`row' = (2*ttail(e(df), abs(_b[`x']/_se[`x']))) F`row' = matrix(e(N))
loc row = `row' + 1
}
I now want to run the analysis, sorting first my [indep var] by ethnicity. I have created a new variable "ChineseOnly" and coded it as Chinese 0 and Others 1. My new code is:
Sort Chinese Only
putexcel set "directory", sheet("name")modify
putexcel A1=("Variable") B1 = ("b") C1=("ll") D1=("ul") E1=("P")
loc row = 2
foreach x of varlist [indep var] {
by ChineseOnly: glm [dep var] `x',family(gaussian) link(identity) vce(robust)
putexcel A`row' = ("`x'") B`row' = (_b[`x']) C`row' = (_b[`x']-1.96*_se[`x']) D`row' = (_b[`x']+1.96*_se[`x']) E`row' = (2*ttail(e(df), abs(_b[`x']/_se[`x']))) F`row' = matrix(e(N))
loc row = `row' + 1
}
The analysis is running fine, however the put excel is not. STATA is only exporting the last set of GLM results. So for example if I have one indep variable, there will be two sets of GLM results 1.indep variable + Chinese (coded as 0) and 2. indep variable + Others (coded as 1), however STATA is only exporting for the last set of GLM results produced in this case being 2.indep variable + Others.
I can not work out how to alter the put excel so that it exports all sets of results for the macro.
Any advice would be greatly appreciated as I need to run the analysis on a large list of dep variables.
thanks!
Mel
Comment