Announcement

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

  • creating multiple histograms using a loop

    Hi all,
    i have 26 variables that i have log transformed using the code below.
    Code:
    foreach var of varlist age-pulse {
       gen ln`var' = log(`var')
       }
    I now want to create histograms with ND line to inspect the normality. i have used the code below but it is not working. i am in the path of learning Stata so it a painful trip

    Code:
    local j = 1
    local names
    foreach var of lnage-lnpulse {
         hist  `var', normal, name(graph`j')
         local names `names' graph`j'
         local ++j
    }
    
    graph combine `names'
    Stat 15.1 on Mac
    Last edited by abdelilah arredouani; 20 Jan 2019, 04:42.

  • #2
    Check the help of foreach again.

    Code:
     
     foreach var of var lnage-lnpulse

    Comment


    • #3
      Thanks Nick
      i changed the code but i get error: invalid name
      Code:
       local j = 1 local names foreach var of varlist lnage-lnpulse {  
         hist  `var', normal, name(graph`j')  
         local names `names' graph`j'    
       local ++j
      }
       graph combine `names'

      Comment


      • #4
        Set the trace on

        Code:
        set trace on
        execute again,
        and see exactly where and exactly about what Stata is complaining. (There are so many names in this block of code that noone knows which exactly of the many names is generating the error.)

        Comment

        Working...
        X