Announcement

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

  • Replace if not found within a loop

    Dear all,
    I am trying to bottom and top coding the household income for each country - wave.
    I am using the following loop that I already successfully used with another data source:
    levelsof country, local(c)
    levelsof wave, local(w)
    foreach country in `c' {
    foreach wave in `w' {
    sum hi100_equ [aw=new_weight] if country==`country' & wave==`wave', det
    local bottom_hi=r(mean)/100
    sum hi100_eur [aw=new_weight] if country==`country' & wave==`wave', det
    local top_dhi=10*r(p50)
    disp `bottom_hi'
    disp `top_hi'
    replace adjusted_hi=`top_hi' if hi100_eur>`$top_hi' & country==`country' & wave==`wave'
    replace adjusted_hi=`bottom_hi' if hi100_eur<`$bottom_hi' & country==`country' & wave==`wave'
    }
    }
    I want to replace the income below the 1% of the equivalised household income with that 1%, and those greater than 10 times the median of non-equivalised with the value corresponding to the 10 times median.
    However, Stata returns the following error: if not found.
    I cannot understand what's the error, can anyone help me?
    Thank you

  • #2
    The dollar signs make no sense. You are mushing together syntax for global and local macros.

    Comment


    • #3
      in addition, note that there are no locals called country or wave - according to the first two lines of your code, those should be c and w

      Comment


      • #4
        Rich Goldstein No; that looks OK. The locals are defined by the foreach loops.

        Comment


        • #5
          correct - sorry for that-

          Comment


          • #6
            Originally posted by Nick Cox View Post
            The dollar signs make no sense. You are mushing together syntax for global and local macros.
            True, thank you!

            Comment

            Working...
            X