Announcement

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

  • Printing the value of a local variable when using estadd

    Hello,

    I am trying to use estadd to export to Latex the value of a Chow test that I calculate in a loop in Stata. I share a simplified reproducible example below.

    HTML Code:
    forvalues i = 1/5 {
    
    eststo: quietly reg price mpg if rep78 == `i'
        scalar RSS`i' = e(rss)
        scalar N`i'   = e(N)
        scalar nmb`i' = RSS`i' + N`i'
        estadd local number "nmb`i'"
    }
    
    esttab, s(N number r2_a,label("N" "Just a Number" "Adjusted R2"))
    The problem that I am facing is that when I export it to Latex, the output that I have is the following:

    Click image for larger version

Name:	stata.png
Views:	1
Size:	20.5 KB
ID:	1713784


    When instead I need the actual number of the "nmb" scalars to appear. There is clearly an issue with the way I call the local variables in the line
    HTML Code:
    estadd local number "nmb`i'"
    . By the way, the correct results are the following:

    HTML Code:
    nmb1 = 2
    nmb2 = 50336485
    nmb3 = 2.366e+08
    nmb4 = 47043743
    nmb5 = 36471571
    Thanks for your help

  • #2
    estout is from SSC (FAQ Advice #12). What if on the other hand I wanted my local to hold the element "nmb1"? Should Stata stop me because there is a scalar with the same name? You have to evaluate the scalar if you want the local to take its value.

    Code:
    scalar nmb1= 27
    local number nmb1
    di "`number'"
    
    
    local number `=nmb1'
    di "`number'"

    Res.:

    Code:
    . scalar nmb1= 27
    
    .
    . local number nmb1
    
    .
    . di "`number'"
    nmb1
    
    .
    .
    .
    .
    .
    . local number `=nmb1'
    
    .
    . di "`number'"
    27
    Last edited by Andrew Musau; 16 May 2023, 08:46.

    Comment


    • #3
      Thanks, but I figured that I should pass "nmb" as a scalar directly instead of a local:
      HTML Code:
      estadd scalar number = RSS`i' + N`i'
      . It simplifies the code quite a lot

      Comment

      Working...
      X