Announcement

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

  • Esttab - numerical format of N cannot be changed using scalars(N) sfmt()

    Dear Statalist members,

    When using esttab from SSC (with Stata version 14.1), I fail to change the numerical format (use thousands separator) of the number of observations, N, provided I only use the esttab options scalars() and sfmt() and don't fall back on estout options such as stats(, fmt()). I would like to stick to the original esttab options in order to not disable further esttab options by using stats(), as explained in the estout help.
    The following example should illustrate the problem:

    set obs 1000
    gen x=rnormal()
    gen y=rnormal()

    reg y x
    eststo est1

    esttab est1 using Esttab_test.txt, scalars(N) sfmt(%9.0fc)
    *Here, thousands separator is not displayed in the created file.
    esttab est1 using Estout_test.txt, stats(N, fmt(%9.0fc))
    *Here, it is displayed.

    Is there any way to change the format of N using only esttab options? I have already extensively studied the esttab/estout help and searched the internet, but couldn't find a solution. Thanks for any help.

  • #2
    Hi, it might probably be late for you but others may have the same problem.
    Following this post (https://kb.iu.edu/d/axqn ), you coudl try using stats(N, fmt(%9.0gc)). That is, change your 'f' for a 'g', instead of working with a real number, use a general.
    Remember
    The variable xx in the format %xx.yy should be equal to or longer than the maximum character length of a value, including commas and a period; otherwise, the command will not work.

    Comment


    • #3
      Santiago Cantillo The OP wants to avoid using stats option. As per the documentation of esttab, taking the OP's example, the following should work but does not.

      Code:
      set obs 1000
      gen x=rnormal()
      gen y=rnormal()
      
      reg y x
      eststo est1
      
      esttab est1, scalars(N) sfmt(%9.0fc) 
      *Here, thousands separator is not displayed in the created file
      Code:
      . esttab est1, scalars(N) sfmt(%9.0fc) 
      
      ----------------------------
                            (1)   
                              y   
      ----------------------------
      x                 -0.0132   
                        (-0.43)   
      
      _cons              0.0227   
                         (0.74)   
      ----------------------------
      N                    1000   
      ----------------------------
      t statistics in parentheses
      * p<0.05, ** p<0.01, *** p<0.001
      
      . 
      . *Here, thousands separator is not displayed in the created file
      The following works fine

      Code:
      esttab est1, stats(N, fmt(%9.0fc))
      Code:
      . esttab est1, stats(N, fmt(%9.0fc))
      
      ----------------------------
                            (1)   
                              y   
      ----------------------------
      x                 -0.0132   
                        (-0.43)   
      
      _cons              0.0227   
                         (0.74)   
      ----------------------------
      N                   1,000   
      ----------------------------
      t statistics in parentheses
      * p<0.05, ** p<0.01, *** p<0.001
      My thoughts are that the problem arises because the display format of scalars in ereturn list cannot be changed. If it is a matter of life and death, the OP may define a macro which allows string inputs and place this in ereturn list.

      Code:
      estadd local Obs "1,000"
      esttab est1, scalars(Obs) noobs
      Code:
      . esttab est1, scalars(Obs) noobs
      
      ----------------------------
                            (1)   
                              y   
      ----------------------------
      x                 -0.0132   
                        (-0.43)   
      
      _cons              0.0227   
                         (0.74)   
      ----------------------------
      Obs                 1,000   
      ----------------------------
      t statistics in parentheses
      * p<0.05, ** p<0.01, *** p<0.001

      Comment


      • #4
        Andrew Musau in your code if I want to add a scalar to show if the fixed effect was used and then also format the number of observations as you you have shown, how do we do that? Because when I include the local macro names for the scalars in the stats option and also use the fmt option, it throws an error.

        Comment


        • #5
          if I want to add a scalar to show if the fixed effect was used and then also format the number of observations as you you have shown, how do we do that?
          Just use estout's -stats()- option that gives you the desired display format in addition to its -indicate()- option. Is there a reason that you don't want to use estout's options? Otherwise, I do not see any obvious reason for your error. Provide an example replicating the error if you need specific code suggestions.
          Last edited by Andrew Musau; 14 Oct 2020, 02:23.

          Comment


          • #6
            Originally posted by Andrew Musau View Post

            Just use estout's -stats()- option that gives you the desired display format in addition to its -indicate()- option. Is there a reason that you don't want to use estout's options? Otherwise, I do not see any obvious reason for your error. Provide an example replicating the error if you need specific code suggestions.
            Yes, I am using esttab's stats option. But it seems it does not allow both scalars and formating. Here is my code, probably it will help you better understand my problem:
            Code:
            reg std_score treated sex repeater, cluster(schoolid)
            eststo model1
            estadd local yfe "No"
            estadd local ufe "No"
            
            reg std_score treated sex repeater i.year, cluster(schoolid)
            eststo model2
            estadd local yfe "Yes"
            estadd local ufe "No"
            
            reg std_score treated sex repeater i.year i.schoolid, cluster(schoolid)
            eststo model3
            estadd local yfe "Yes"
            estadd local ufe "Yes"
            
            esttab model*, f ///
            keep(treated sex) varlabels(treated Treated sex Sex) ///
            cells(b(star fmt(2)) se(par fmt(2))) ///
            mtitles("Test Score" "Passing" "Top Uni") collabels(none) numbers ///
            s(yfe ufe N, label("Year FE" "School FE" "Observations")) ///
            sfmt(%9.0fc) ///
            style(tex) starlevels("*" 0.10 "**" 0.05 "***" 0.01) replace
            I want to format N such that it is separated by a comma in each 100. Thanks for taking the time to take a look at this.

            Comment


            • #7
              s() in esttab is read as scalars(). So use

              Code:
              stats(yfe ufe N, label("Year FE" "School FE" "Observations")) sfmt(%9.0fc)

              Comment

              Working...
              X