Announcement

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

  • Replacing string local macro with numbers to string local macro with formatted numbers

    I would like to change the local macro
    PHP Code:
    local add_range "[ 2.74571, 5.75474]" 
    to
    PHP Code:
    local add_range "[2.74 - 5.75]" 

  • #2
    Within the relatively obscure material revealed by -help extended_fcn-, there is documentation for various useful manipulations with local macros. Were it not for StataList, I'd never have known about that stuff. There, among other things, one can find out how to put the produced by a -display- command into a macro, which can be useful, if somewhat messy. In the current case, a one line solution is:
    Code:
    local add_range: display  = "[" %4.2f 2.74571 ", " %4.2f 5.75474 "]"
    display "`add_range'"

    Comment


    • #3
      Easier to do the formatting before you combine afterwards.

      Your two values come from somewhere.

      Code:
      . local lower 2.74571
      
      . local upper 5.75474
      
      . local wanted [
      
      . local wanted `wanted' `: di %3.2f `lower''
      
      . local wanted `wanted' ,
      
      . local wanted `wanted' `: di %3.2f `upper''
      
      . local wanted `wanted' ]
      
      . di "`wanted'"
      Last edited by Nick Cox; 01 Feb 2023, 08:31.

      Comment

      Working...
      X