Announcement

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

  • Estout / esttab: Include both variables labels from a foreach loop in the table title

    I am using a foreach loop incombination with the estout package in Stata to automatically report a lot of regressions. The reporting works nicely with one exception. When using
    Code:
     `var lab `j'
    with two independent variables, the variable labels do not get printed in the title because j is assigned to two independent variables and estout returns the following message "race not allowed" and "never_married not allowed". Is there a way to include both variable labels in the title? I tried subsetting the j variable using `j[1]' but it only returns the error "nothing found where name expected".

    Code:
    webuse nlsw88.dta, clear
    
    local dvs wage hours
    local alls `aiv' `biv'
    
    local c 0
    foreach i of local dvs {
    local c = `c' + 1
    local f = 0
    foreach j in "age race" "married never_married" {
    local f = `f' + 1
    eststo model`c'`f': reg `i' `j'
    esttab model`c'`f' using Regressionloops.rtf, append se label onecell nomtitles nogaps title(\page "Title DV = `: var lab `i'' & IV = `: var lab `j''")
    
    }
    eststo drop *
    }
    Stata Version: 8
    OS: Windows 10
    __________________________________________________ __________

    Cheers, Felix
    Stata Version: MP 18.0
    OS: Windows 11

  • #2
    I can get this to work:
    Code:
    webuse nlsw88.dta, clear
    
    local dvs wage hours
    local alls `aiv' `biv'
    
    local c 0
    foreach i of local dvs {
    local c = `c' + 1
    local f = 0
    foreach j in "age race" "married never_married" {
    local f = `f' + 1
    eststo model`c'`f': reg `i' `j'
    tokenize `j'
    esttab model`c'`f' , append se label onecell nomtitles nogaps title("\page Title DV = `: var lab `i'' & IV = `: var lab `1'' `: var lab `2''")
    *
    
    }
    eststo drop *
    }
    but when I add the using part, it fails due to "too few quotes"

    not sure why

    Comment


    • #3
      actually it does work. just changed the name of the file and all worked properly.

      Comment


      • #4
        Dear George,
        this worked, when I copy pasted your code and rewrote my code from scratch. Thank you so much!
        __________________________________________________ __________

        Cheers, Felix
        Stata Version: MP 18.0
        OS: Windows 11

        Comment

        Working...
        X