Announcement

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

  • Creating quartiles using loop for 25 continuous independent variables

    Any suggestion how to fix this loop ?
    I am trying to create quartiles for 25 continuous independent variables for use in logistic regression in order to compare the lowest quartile with highest quartile?
    Click image for larger version

Name:	STATA post 1.JPG
Views:	1
Size:	33.8 KB
ID:	1480861

  • #2
    what kind of error message do you get?

    I can not see, that the part after the comma i documented in the manual.
    Perhaps something like:

    Code:
    foreach x of local `consentrations' {
        foreach n of numlist 25 50 75 100 {
            centile(`x'), c(`n')
           return list
           local q`n' = `r(c_1)'
        }
    }
    
    macro dir
    Last edited by Dennis Lund Hansen; 28 Jan 2019, 05:58.

    Comment


    • #3
      You should report what Stata returned to you when you tried to execute the loop.

      You obviously have errors in the syntax if -centile-.

      And it is easier for me to write this from scratch than to fix what you have. Something like this:

      Code:
      foreach x in `concentrations' {
      xtile quartile`x' = `x', nq(4)
      }

      Comment


      • #4
        Several bugs there, starting with trying to use local macros that don't exist. But the big picture is that to create quartile-based bins, you should use a different command.

        Code:
        foreach x of local concentrations { 
            xtile quartile_`x'=`x',  nq(4) 
        }

        Comment

        Working...
        X