Announcement

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

  • Failure to store regression data (b, pvalue, CI) in a new variable in the full database

    Hi,

    I got help from the forum to solve my problem and it was great ("How to store p-value and CI in a new variable in beaches-winsten regression?"). I managed to carry out my analyses, but now in other banks I can't reproduce it completely.

    The command runs to some extent (as in the example generated by dataex). I believe that the error can occur in some groups of code_obge because the values over time are similar or even the same.
    How do I make it run full and "ignore" regressions that give error?

    ** version Stata 17

    Code used:

    xtset codigo_ibge ano

    levelsof codigo_ibge, local(ids)
    gen b = .
    gen ll = .
    gen ul = .
    gen pvalue = .

    foreach i of local ids {
    capture prais logprev_iac_ ano if codigo_ibge == `i'
    if c(rc) == 0 {
    matrix M = r(table)
    foreach x in b ll ul pvalue {
    quietly replace `x' = M["`x'", "ano"] if codigo_ibge == `i'
    }
    }
    else if inlist(c(rc), 2000, 2001) {
    continue
    }
    else {
    display as error "Unexpected error: codigo_ibge == `i'"
    exit(c(rc))
    }
    }

    gen apc_iac= (-1+(10^ b))*100
    gen apc_min_iac= (-1+(10^ll))*100
    gen apc_max_iac= (-1+(10^ul))*100





    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long codigo_ibge int ano float prev_iac_ byte porte_municipio float(logprev_iac_ b ll ul pvalue apc_iac apc_min_iac apc_max_iac)
    316245 2015       100 0         2   -.008813011 -.027603345  .00997732 .2323614    -2.0088198  -6.15813 2.3239558
    316245 2016  91.66666 0 1.9622114   -.008813011 -.027603345  .00997732 .2323614    -2.0088198  -6.15813 2.3239558
    316245 2017      87.5 0  1.942008   -.008813011 -.027603345  .00997732 .2323614    -2.0088198  -6.15813 2.3239558
    316245 2018  91.30434 0 1.9604914   -.008813011 -.027603345  .00997732 .2323614    -2.0088198  -6.15813 2.3239558
    316245 2019  90.47619 0 1.9565343   -.008813011 -.027603345  .00997732 .2323614    -2.0088198  -6.15813 2.3239558
    316447 2015       100 0         2 -2.458474e-14 -.016400341 .016400341        1 -5.662137e-12 -3.705904  3.848527
    316447 2016       100 0         2 -2.458474e-14 -.016400341 .016400341        1 -5.662137e-12 -3.705904  3.848527
    316447 2017  91.66666 0 1.9622114 -2.458474e-14 -.016400341 .016400341        1 -5.662137e-12 -3.705904  3.848527
    316447 2018       100 0         2 -2.458474e-14 -.016400341 .016400341        1 -5.662137e-12 -3.705904  3.848527
    316447 2019       100 0         2 -2.458474e-14 -.016400341 .016400341        1 -5.662137e-12 -3.705904  3.848527
    316470 2015  94.11765 2  1.973671             .           .          .        .             .         .         .
    316470 2016   94.3662 2 1.9748164             .           .          .        .             .         .         .
    316470 2017  95.06173 2 1.9780058             .           .          .        .             .         .         .
    316470 2018  95.52238 2  1.980105             .           .          .        .             .         .         .
    316470 2019      87.5 2  1.942008             .           .          .        .             .         .         .
    316520 2015       100 0         2             .           .          .        .             .         .         .
    316520 2016        80 0   1.90309             .           .          .        .             .         .         .
    316520 2017        80 0   1.90309             .           .          .        .             .         .         .
    316520 2018  95.83334 0 1.9815166             .           .          .        .             .         .         .
    316520 2019  90.90909 0 1.9586073             .           .          .        .             .         .         .
    316557 2015 66.666664 0 1.8239087             .           .          .        .             .         .         .
    316557 2016       100 0         2             .           .          .        .             .         .         .
    316557 2017        90 0 1.9542425             .           .          .        .             .         .         .
    316557 2018  90.90909 0 1.9586073             .           .          .        .             .         .         .
    316557 2019 66.666664 0 1.8239087             .           .          .        .             .         .         .
    316680 2015       100 0         2             .           .          .        .             .         .         .
    316680 2016  96.15385 0 1.9829667             .           .          .        .             .         .         .
    316680 2017      87.5 0  1.942008             .           .          .        .             .         .         .
    316680 2018       100 0         2             .           .          .        .             .         .         .
    316680 2019  92.85714 0 1.9678153             .           .          .        .             .         .         .
    end
    label values porte_municipio porte_municipio
    label def porte_municipio 0 "pequeno I", modify
    label def porte_municipio 2 "medio", modify
    ------------------ copy up to and including the previous line ------------------

  • #2
    Perhaps the suggested changes in red will start you in a useful direction.
    Code:
    foreach i of local ids {
        capture prais logprev_iac_ ano if codigo_ibge == `i'
        if c(rc) == 0 {
            matrix M = r(table)
            foreach x in b ll ul pvalue {
                quietly replace `x' = M["`x'", "ano"] if codigo_ibge == `i'
            }
        }
        else if inlist(c(rc), 2000, 2001) {
            continue
        }
        else {
            display as error "Unexpected error: codigo_ibge == `i'  error code"  c(rc)
        }
    }

    Comment


    • #3
      Hi, thank you so much William!

      It worked really well!

      Comment

      Working...
      X