Announcement

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

  • #16
    And if you want to save your data and don't need the temporary variables after clonevar any more, also drop the temporary variables after clonevar or before saving your data.

    Comment


    • #18
      Here's one way to have summarize show a specified variable name. Not efficient, not elegant, but a sufficient proof of concept:
      Code:
      program summarize_as
          
          version 18
          
          syntax varname , as(name)
          
          preserve
          
          capture drop `as'
          
          rename `varlist' `as'
          
          summarize `as'
          
      end
      Here's how you use it in a program with temporary names:
      Code:
      program foo
          
          version 18
          
          syntax varlist
          
          tempvar price
          
          generate `price' = 42
          
          summarize_as `price' , as(price)
          
      end
      Here's an example:
      Code:
      . sysuse auto
      (1978 automobile data)
      
      . foo price
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
             price |         74          42           0         42         42
      
      . summarize price
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
             price |         74    6165.257    2949.496       3291      15906

      Comment


      • #19
        Here's a slightly more efficient summarize_as. You could do (much) better but probably not wihthout (much) more programming:
        Code:
        program summarize_as
            
            version 18
            
            syntax varname , as(name)
            
            tempname tmpframe
            
            frame put `varlist' , into(`tmpframe')
            
            frame `tmpframe' {
                
                rename `varlist' `as'
                
                summarize `as'
                
            }
            
        end

        Comment

        Working...
        X