Announcement

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

  • Store a value

    Hello,

    let's say I have a variable x with data from 1 to 10. How can Stata save the maximum of x (10) as placeholder, which can be used in an if loop or forval i=1/.....

    Thank you!

  • #2
    Code:
    sum x, meanonly
    local max = r(max)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Stata doesn't save scalars and macros with .dta files - -save- isn't a "workspace save". If you are very ambitious this link

      https://www.statalist.org/forums/for...or-alternative

      suggests how you might add machine readable information to a dta file using -notes- and -notes_-. See also

      https://www.stata.com/help.cgi?notes_

      Comment


      • #4
        Maarten showed how you can save this to a local, but generally you typically do not need to save this most of the time. This is because the calculation is fast, and it is more headache to carry the result, rather than just calculate it again on the fly.

        Just use the

        summarize x, meanonly

        immediately before your loop, and directly refer to r(max).

        Comment

        Working...
        X