Announcement

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

  • option if not allowed with egen command

    Hello,

    I try to use the egen command to define a percentile for different agreements (here called PTA_*). So I use the following loop:

    Code:
    forval v=1/955 {
          capture confirm var PTA_`v'_j
          if _rc == 0 {
                
                 bysort prod year : egen p75KL_`v' = pctile(diffKL_jw), p(75) if PTA_`v'_j == 1
                 gen extKL_`v' = 1 if p75KL_`v' <= diff_jw & PTA_`v'_j == 1
                       
          }
    }
    I get an error message saying that the option if is not allowed. The problem is the first "if" (in the egen command). I don't understand why I get this message since the egen command is compatible with if option.
    Could anyone let me know how can I fix this?

  • #2
    if isn't an option in any case. It's a qualifier and belongs before the comma:


    Code:
       bysort prod year : egen p75KL_`v' = pctile(diffKL_jw) if PTA_`v'_j == 1, p(75)
    Last edited by Nick Cox; 08 May 2018, 02:26.

    Comment


    • #3
      Ok I get it. Works perfectly now. Thank you Nick

      Comment

      Working...
      X