Announcement

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

  • Help for eststo and esttab

    Hello everyone,

    I’m a beginner in STATA, and my professor requires us to create a table that combines Year Fixed Effects, Max VIF, and AUC.
    I have worked on these elements separately, but I’m struggling with the fixed effects and how to combine all the data into one table.
    Below, I have listed my work so far, along with the differences between my results and what I aim to achieve.

    Thanks for your reading and any possible answer.


    Here is my work and the code I used:

    AUC:
    logit failed cfta nitl clta cta cacl qarev if fyear==2018
    lroc
    logit failed cfta nitl clta cta cacl qarev if fyear==2019
    lroc
    logit failed cfta nitl clta cta cacl qarev if fyear==2020
    lroc
    logit failed cfta nitl clta cta cacl qarev if fyear==2021
    lroc
    logit failed cfta nitl clta cta cacl qarev if fyear==2022
    lroc

    VIF:
    logit failed cfta nitl clta cta cacl qarev
    vif, uncentered

    Fixed Effect:
    I saw some people suggest to use common: logit failed cfta nitl clta cta cacl qarev i.fyear, vice(robust)
    But I only result "option vice() not allowed" so I'm not sure is it nascency or I should install any other package.

    Table:
    eststo: quietly logit failed cfta nitl clta cta cacl qarev i.fyear if fyear==2018
    eststo: quietly logit failed cfta nitl clta cta cacl qarev i.fyear if fyear==2019
    eststo: quietly logit failed cfta nitl clta cta cacl qarev i.fyear if fyear==2020
    eststo: quietly logit failed cfta nitl clta cta cacl qarev i.fyear if fyear==2021
    eststo: quietly logit failed cfta nitl clta cta cacl qarev i.fyear if fyear==2022
    eststo: quietly logit failed cfta nitl clta cta cacl qarev i.fyear
    esttab , pr2 t(2) b(3) nogap compress star(* 0.10 ** 0.05 *** 0.01) label title(My regression table) nonumbers mtitles("2018" "2019" "2020" "2021" "2022" "COMBINED")
    Click image for larger version

Name:	2025-01-05 142801.png
Views:	1
Size:	46.2 KB
ID:	1770302




    However, the reference code from my professor is like:
    *regressions
    eststo: quietly logit failed cftd tdta recta mkvalta i.gsector if fyear==2008
    eststo: quietly logit failed cftd tdta recta mkvalta i.gsector if fyear==2007
    eststo: quietly logit failed cftd tdta recta mkvalta i.gsector if fyear==2006
    eststo: quietly logit failed cftd tdta recta mkvalta i.gsector if fyear==2005
    eststo: quietly logit failed cftd tdta recta mkvalta i.gsector if fyear==2004
    eststo: quietly logit failed cftd tdta recta mkvalta i.gsector i.fyear

    *output to stata
    esttab , pr2 t(2) b(3) nogap compress star(* 0.10 ** 0.05 *** 0.01) label title(My regression table) nonumbers mtitles("2008" "2007" "2006" "2005" "2004" "COMBINED") addnote("footnotes")

    *output to txt
    esttab using output.rtf, replace pr2 t(2) b(3) nogap compress star(* 0.10 ** 0.05 *** 0.01) label title(My regression table) nonumbers mtitles ("2008" "2007" "2006" "2005" "2004" "COMBINED") addnote("footnotes")
    Click image for larger version

Name:	2025-01-05 143205.png
Views:	1
Size:	138.2 KB
ID:	1770303



    Last edited by Jerry Li; 05 Jan 2025, 08:40.

  • #2
    1. change vice to vce
    2. don't need i.year in the individual year regressions, just the combined.
    3. you don't have i.gsector in the individual year regressions.
    4. you can drop gsector coefficient using "drop" in esttab.
    5. you can use xtlogit to absorb the sectors if there are many.


    Something like this gets it done, but probably better ways to get the max vif.
    Code:
    clear all
    sysuse auto, clear
    g group = runiform()>0.5
    
    eststo e1: logit foreign mpg price weight i.rep78 if group , vce(robust)
    estadd local pr2 = round(e(r2_p),0.01)
    lroc
    local auc : di %5.3f r(area)
    estadd scalar AUC = `auc'
    vif , uncentered
    local k = e(df_m)
    local maxvif = 0
    forv i = 1/`k' {
        local vif = round(r(vif_`i'),0.001)
        if `vif' > `maxvif' {
            local maxvif =`vif'
        }
    }
    estadd scalar MVIF = `maxvif'
    estadd local rep78_fe "Yes"
    estadd local group_fe "No"
    eststo e2: logit foreign mpg price weight i.rep78 if !group, vce(robust)
    estadd local pr2 = round(e(r2_p),0.01)
    lroc
    local auc : di %5.3f r(area)
    estadd scalar AUC = `auc'
    vif , uncentered
    local k = e(df_m)
    local maxvif = 0
    forv i = 1/`k' {
        local vif = round(r(vif_`i'),0.001)
        if `vif' > `maxvif' {
            local maxvif =`vif'
        }
    }
    estadd scalar MVIF = `maxvif'
    estadd local rep78_fe "Yes"
    estadd local group_fe "No"
    eststo e3: logit foreign mpg price weight i.rep78 i.group , vce(robust)
    estadd local pr2 = round(e(r2_p),0.01)
    lroc
    local auc : di %5.3f r(area)
    estadd scalar AUC = `auc'
    vif , uncentered
    local k = e(df_m)
    local maxvif = 0
    forv i = 1/`k' {
        local vif = round(r(vif_`i'),0.001)
        if `vif' > `maxvif' {
            local maxvif =`vif'
        }
    }
    estadd scalar MVIF = `maxvif'
    estadd local rep78_fe "Yes"
    estadd local group_fe "Yes"
    esttab e1 e2 e3 , stats(N pr2 rep78_fe group_fe AUC MVIF) drop(*rep78 *group) mtitle(Group1 Group2 Combined)

    Comment


    • #3
      Thank you for your help! I'll give it a try later.
      Wishing you a wonderful holiday!

      Comment


      • #4
        This is cleaner. A program will do all the estadd and you just call it after the regression. It has two arguments for the FE where type in the YES or NO.

        Code:
        clear all
        sysuse auto, clear
        g group = price>5000
        
        *******************************************************
        ** PROGRAM: dostats
        *******************************************************
        capture program drop dostats
        program dostats, eclass
            args fe1 fe2
            quietly {
            local pr : di %5.3f e(r2_p)
            estadd local pr2 =`pr'
            lroc
            local auc : di %5.3f r(area)
            estadd scalar AUC = `auc'
            vif , uncentered
            local maxvif = 0
            forv i = 1/`e(df_m)' {
                local vif = round(r(vif_`i'),0.001)
                if `vif' > `maxvif' {
                    local maxvif =`vif'
                }
            }
            di `maxvif'
            estadd scalar MVIF = `maxvif'
            estadd local UNIT_FE "`fe1'"
            estadd local TIME_FE "`fe2'"
            }
        end
        
        *******************************************************
        ** ESTIMATE
        *******************************************************
        eststo e1: qui logit foreign mpg price weight if group , vce(robust)
        dostats YES NO
        eststo e2: qui logit foreign mpg price weight if !group, vce(robust)
        dostats YES NO
        eststo e3: qui logit foreign mpg price weight i.group , vce(robust)
        dostats YES YES
        esttab e1 e2 e3 , stats(N pr2 UNIT_FE TIME_FE AUC MVIF) drop(*group) mtitle(Group1 Group2 Combined)

        Comment

        Working...
        X