Announcement

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

  • Variable __000000 already defined

    Hi,

    I do have a puzzling problem. I am computing gini coefficients using the bootstrap command to get standard errors. The program does not run because it stops, when trying to create a "__000000" variable that has been already created. Here is the program:

    global pauv "C:\Users\Inégalités et pauvreté\Logs\Révision"
    global IP "C:\Users\Inégalités et pauvreté\Bases\Révision"

    clear all
    capture log close
    set more off

    cap program drop _all

    * Programmes

    program define inegest, rclass
    args var
    ineqdeco `var' [fw=fweight]
    global gini=$S_gini*100
    global r9010=$S_9010
    global r7525=$S_7525
    global logdev=$S_i0
    global theil=$S_i1

    return scalar gini = $gini
    return scalar r9010 = $r9010
    return scalar r7525 = $r7525
    return scalar logdev = $logdev
    return scalar theil = $theil

    end

    log using "$pauv\inequality_se.log", replace

    use "${IP}/base_inegpauv.dta", clear

    global bootparm 250

    svyset dr, strata(milieu) weight(poids_1_p12) vce(linearized) singleunit(missing) || idmen_c

    outreg, clear
    global typdep dep_pcap_total_men dep_pcap_nalim_men dep_pcap_alimt_men
    global rows dep_pcap_total_men\dep_pcap_nalim_men\dep_pcap_ali mt_men

    foreach var in $typdep {
    set seed 34523
    bootstrap gini=r(gini) r9010=r(r9010) r7525=r(r7525) logdev=r(logdev) theil=r(theil), reps($bootparm) strata(milieu) cluster(dr idmen_c): inegest "`var'"
    matrix b_`var' = e(b)
    matrix se_`var' = e(se)
    matrix `var'=b_`var'[1,1],se_`var'[1,1],b_`var'[1,2],se_`var'[1,2],b_`var'[1,3],se_`var'[1,3],b_`var'[1,4],se_`var'[1,4],b_`var'[1,5],se_`var'[1,5]
    matrix rownames `var'="`var'_est"
    }
    matrix balance=$rows

    frmttable using "$pauv\table 3_se_pcap.doc", replace statmat(balance) sdec(2, 2, 2, 2, 2) substat(1) ///
    title(Table 3b: "Inequality measures with SE") coljust(l c ) lan ///
    ctitles("" , Gini, 90/10, 75/25, "mean log dev", theil) varl ///
    basefont(fs10) titlfont(fs11 b) colwidth(20 9 9 9 9 9)
    log close


    and here is what I get when running the program (I only reproduce the bottom part of the listing):

    . foreach var in $typdep {
    2. set seed 34523
    3. bootstrap gini=r(gini) r9010=r(r9010) r7525=r(r7525) logdev=r(logdev) theil=r(theil), reps($boo
    > tparm) strata(milieu) cluster(dr idmen_c): inegest "`var'"
    4. matrix b_`var' = e(b)
    5. matrix se_`var' = e(se)
    6. matrix `var'=b_`var'[1,1],se_`var'[1,1],b_`var'[1,2],se_`var'[1,2],b_`var'[1,3],se_`var'[1,3],b
    > _`var'[1,4],se_`var'[1,4],b_`var'[1,5],se_`var'[1,5]
    7. matrix rownames `var'="`var'_est"
    8. }
    (running inegest on estimation sample)
    variable __000000 already defined
    r(110);


    I am currently using Stata 14. But the problem is the same when running Stata 13.

    I used the trace command and I found that the problem is due to an instruction in the bootstrap.ado file, on line 281:

    mark `touse' `cmdif' `cmdin'

    I somehow solved the problem in creating a copy of this ado file and putting it in the C:\ado\personal directory (renaming it "bootstrapm.ado") and adding a

    cap drop __000000

    instruction before the mark instruction. But it is obviously not really satisfactory, and I would appreciate to get some help solving this matter in a more systematic and less empirical way.

    Best,

    Philippe

  • #2
    I can't see what's problematic here but I note that recent versions of ineqdeco (SSC, as you are asked to explain) leave behind r-class results. So your own program reading in globals and emitting r-class results is unneeded.

    Comment


    • #3
      Can you provide sample data using dataex that reproduces this problem? It doesn't have to be your real data, it just has to display the problem that you're experiencing. See the FAQ for more info on providing data. This is a complex and specific enough issue that it's pretty much impossible to troubleshoot without having an example to play with.

      You don't provide enough output to tell for sure whether this happens on the second iteration through the loop or the first. If you remove the loop and just run the bootstrap on the first of your variables does bootstrap perform as expected?

      My suspicion is that ineqdeco is creating a temporary variable that is conflicting with the one that bootstrap is trying to create. It looks like both use the tempvar touse. I think normally this isn't a problem because the tempvars are cleared when a program finishes running. Someone who is more familiar with how Stata handles temporary variables can perhaps comment more thoroughly on this but basically I think the touse var from ineqdeco still exists by the time bootstrap runs so there's an error when bootstrap tries to create it.

      Your work around is one solution. I think you could also modify the ineqdeco.ado file to use a different name than touse. Someone else may have better suggestions than either of those.

      One other thing to check is whether you get the same error if you use ineqdeco directly with your bootstrap command instead of your program. If that doesn't have the same problem then Nick's point about ineqdeco leaving behind r-class results would mean you could dispense with defining the program.

      Comment


      • #4
        -ineqdeco- and -ineqdec0- return results in r(), as Nick says, and have done so for at least a decade. Nonetheless, I am puzzled why the bootstrap is being used to derive standard errors for these indices. There are programs available on SSC for this based on linearisation methods (and they've been there for years): type -ssc d svylorenz- (for the Gini) and -ssc svygei_svyatk- (Generalised Entropy and Atkinson indices). If you also want SEs for decile or quartile ratios, you could bootstrap using returned results -ineqdeco- but it'd probably be faster to use -summarize, detail-.

        Comment


        • #5
          Dear Nick, Sarah and Stephen,

          Thank's a lot for answering this post. This helps !

          Philippe

          Comment

          Working...
          X