Announcement

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

  • ineqdec0, missing values and error in loop

    Hi everyone,
    I am trying to export a large number of descriptive statistics on household income by country of origin using Ineqdec0 + estout. However, whenever STATA finds missing observations, it interrupts abruptly. Is there a way to avoid this in the loop? Or is there a command to say STATA to keep going if it encounters missing values? I post here the code:

    Code:
    levelsof country_origin, local(ctry)
    
    foreach l of local ctry{
    forvalues j=2005/2011{
    set more off
    matrix C_`j'_`l' = (0,0,0,0)
    forvalues i=1/5{
    foreach v of varlist n_hh_income r_hh_income{
    ineqdec0 `v' if `v'_qtile_`l' == `i' & year == `j' & country_origin == `l'
    matrix Amean = (r(mean))
    matrix Asd = (r(sd))
    matrix Amax= (r(max))
    matrix Agini= (r(gini))
    matrix C_`j'_`l' = (C_`j'_`l'\Amean[1,1], Asd[1,1], Amax[1,1], Agini[1,1])
    }
    }
    matrix list C_`j'_`l'
     
    estout matrix(C_`j'_`l') using income.xls, style(tab) omitted legend label title(Average household income per year) modelwidth(10) varwidth(10) append 
    
    }
    where n_hh_income r_hh_income denote nominal and real average household income in a given year, respectively. Country_origin is a categorical variable indicating the country of origin of individual I and v_qtile_l is the quintile of household income for those whose country of origin is `l'.
    Thank you in advance,
    Andrea

  • #2
    Decide on how many non-missing values you need for a worthwhile result. Call up ineqdec0 if and only if you have enough.

    Code:
    foreach v of varlist n_hh_income r_hh_income{
        quietly count if !missing(`v') & `v'_qtile_`l' == `i' & year == `j' & country_origin == `l'
        if r(N) >= 7 {
            ineqdec0 `v' if `v'_qtile_`l' == `i' & year == `j' & country_origin == `l'
            matrix Amean = (r(mean))
            matrix Asd = (r(sd))
            matrix Amax= (r(max))
            matrix Agini= (r(gini))
            matrix C_`j'_`l' = (C_`j'_`l'\Amean[1,1], Asd[1,1], Amax[1,1], Agini[1,1])}
    }
    Incidentally, you don't need to create matrices to contain scalars only to take them out again.

    Think of it this way. I have a pen. I put it in a box. I want my pen. I take it out of the box. With nothing else said, the boxing was not needed.


    Code:
    ineqdec0 `v' if `v'_qtile_`l' == `i' & year == `j' & country_origin == `l'
    matrix C_`j'_`l' =  C_`j'_`l' \  r(mean), r(sd), r(max), r(gini)
    Also, learn about nullmat() to avoid the pointless initial row of zeros.

    I'll leave as an open question what interest or use there is in calculating inequality measures within income bins!

    Finally, time for you to read the entire FAQ Advice, all the way down to https://www.statalist.org/forums/help#spelling
    Last edited by Nick Cox; 17 Feb 2019, 04:27.

    Comment


    • #3
      Thank you a lot Mr. Cox

      Comment

      Working...
      X