Announcement

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

  • mdepriv : The Relative Deprivation Measure

    Dear all,

    In one of my current paper, I have to calculate the relative deprivation measure by comparing the income of individual i (y) with income of each other individuals in the data (m) and report the following:

    D(y;m)= m-y if m>y (e.g., there is income deprivation)
    0 if m<y (e.g., no relative income deprivation)

    Then I have to weight D by the cumulative proportion of total income at income y, and by the cumulative proportion of the population up to individual with income y, where the population is ranked by income. I have tried to go through the notes of the command "mdepriv" and applied it various of times with no success (please see below). I was thinking maybe to create a dummy variable of deprivation but then it would not calculate the m-y needed for my analysis.

    When I run the mdepriv code as follows

    Code:
    ssc install mdepriv
    
    mdepriv (infinc), gen(s) force
    
    sum s
    
    
    foreach block in "infinc" {qui mdepriv `block´ , method(bv) generate(s`++i´)}
    I keep reciving this error code:

    foreach block in "infinc" {qui mdepriv `block´ , method(bv) generate(s`++i´)}
    program error: code follows on the same line as open brace
    r(198);

    I was thinking creating the code manually but it needs to run for each individual in the data and return value of 0 or m-y?

    I would really appericate your help.
    Thank you in advance for your understanding.
    Regards,

    Natasha.
    Last edited by Louise Jacobs; 05 Dec 2022, 11:46.

  • #2
    Stata has told you that code may not follow on the same line as the open brace { following your foreach command. The output of
    Code:
    help foreach
    shows examples of the correct syntax, and it seems likely that the following will overcome the error Stata reports.
    Code:
    foreach block in "infinc" {
        qui mdepriv `block' , method(bv) generate(s`++i')
    }
    Note that my comments address only the issue of the error code you receive; I have no idea if the results of correcting that error will result in output that is useful for your purposes.

    Added in edit: I corrected
    Code:
    `block´
    in the original to
    Code:
    `block'
    in the code above, and similarly for the ++i.

    To have Stata substitute the value of a local macro
    Code:
     block
    you need to type on your keyboard
    Code:
     `block' 
    where the first character is (on an American English keyboard) the "left single quote" beneath the tilde (~) character below the ESC key, and the final character is the usual "single quote" ("apostrophe") just to the left of the RETURN key. Neither of these are "smart quotes" as understood in programs like Microsoft Word, and in particular the first character is correctly titled the "grave accent".
    Last edited by William Lisowski; 05 Dec 2022, 12:02.

    Comment


    • #3
      Originally posted by William Lisowski View Post
      Stata has told you that code may not follow on the same line as the open brace { following your foreach command. The output of
      Code:
      help foreach
      shows examples of the correct syntax, and it seems likely that the following will overcome the error Stata reports.
      Code:
      foreach block in "infinc" {
      qui mdepriv `block' , method(bv) generate(s`++i')
      }
      Note that my comments address only the issue of the error code you receive; I have no idea if the results of correcting that error will result in output that is useful for your purposes.

      Added in edit: I corrected
      Code:
      `block´
      in the original to
      Code:
      `block'
      in the code above, and similarly for the ++i.

      To have Stata substitute the value of a local macro
      Code:
       block
      you need to type on your keyboard
      Code:
       `block' 
      where the first character is (on an American English keyboard) the "left single quote" beneath the tilde (~) character below the ESC key, and the final character is the usual "single quote" ("apostrophe") just to the left of the RETURN key. Neither of these are "smart quotes" as understood in programs like Microsoft Word, and in particular the first character is correctly titled the "grave accent".
      That is very helpful and clarifying my mistake when running the foreach command. Thank you William.

      Unfortunately, I am still not sure how to solve the situation mentioned in my original post and running this for each individual while asking Stata to return the difference in income value (if derived).

      Regards,

      Comment

      Working...
      X