Announcement

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

  • Scalar

    Hi everyone, I'm fairly new to the use of scalar and I'm having some issue getting it to work: I'm trying to use the results from my last "total" command in my new command in order to automate some calculation, but the scalar I created seem to be blank and I don't understand why. Any idea why that is?
    Click image for larger version

Name:	Screenshot 2023-02-23 at 19.15.03.png
Views:	1
Size:	58.7 KB
ID:	1703132

  • #2
    there is no such returned value from the -total- command as "r(sum)" - rather, all results are returned in the matrix "r(table)"; try the following:
    Code:
    . sysuse auto
    (1978 automobile data)
    r; t=0.01 14:40:51
    
    . total price if for
    
    Total estimation                            Number of obs = 22
    
    --------------------------------------------------------------
                 |      Total   Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
           price |     140463   12297.87      114888.2    166037.8
    --------------------------------------------------------------
    
    . scalar z=r(table)[1,1]
    
    . di z
    140463

    Comment


    • #3
      Thank you! That worked exactly how I wanted!

      Comment


      • #4
        Just a couple other things:
        • return list and ereturn list are useful little commands that show what macros, scalars, matrices, and functions are presently stored in working memory.
        • You don't need to put scalar names in macro delimiters (simply x rather than `x').

        Comment

        Working...
        X