Announcement

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

  • variable not found

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 countrycode str16(yr2001 yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010)
    "AFG" ".."               "4055179566.34981" "4515558808.10994" "5226778808.89209" "6209137624.77181" "6971285594.68013" "9747879531.86311" "10109305182.952"  "12416161048.8412" "15856678596.148" 
    "ALB" "3922100793.5403"  "4348068242.19512" "5611496257.14231" "7184685781.51876" "8052073539.38058" "8896072918.9814"  "10677324144.4289" "12881353507.8539" "12044208085.864"  "11926922828.9911"
    "DZA" "54744712814.8676" "56760355865.0082" "67863828412.6882" "85332581188.6107" "103198223709.439" "117027307540.89"  "134977082623.78"  "171000699876.747" "137211035770.034" "161207270185.25" 
    "ASM" ".."               "512000000"        "524000000"        "509000000"        "500000000"        "493000000"        "518000000"        "560000000"        "675000000"        "573000000"       
    "AND" "1546926174.49664" "1755910031.99699" "2361726862.30248" "2894921777.99851" "3159905484.39249" "3456442102.622"   "3952600602.24473" "4085630584.44412" "3674409558.21061" "3449925738.86069"
    "AGO" "8936063723.20121" "15285594828.418"  "17812704825.1957" "23552047248.4301" "36970918699.2523" "52381006892.038"  "65266452081.386"  "88538610805.3214" "70307166934.3311" "81699556136.6643"
    "ATG" "800481481.481481" "814381481.481481" "856396296.296296" "919729629.62963"  "1022962962.96296" "1157662962.96296" "1312759259.25926" "1370070370.37037" "1228329629.62963" "1148700000"      
    "ARG" "268696750000"     "97724004251.8602" "127586973492.177" "164657930452.787" "198737095012.282" "232557260817.308" "287530508430.568" "361558037110.419" "332976484577.619" "423627422092.49" 
    "ARM" "2118467913.37873" "2376335048.39976" "2807061008.69084" "3576615240.41616" "4900469950.09033" "6384451606.1421"  "9206301700.39619" "11662040713.8753" "8647936747.98704" "9260284937.79781"
    "ABW" "1896648044.69274" "1962011173.18436" "2044134078.21229" "2254748603.35196" "2359776536.31285" "2469832402.23464" "2677653631.28492" "2843016759.77654" "2553631284.9162"  "2453631284.9162" 
    "AUS" "379083932596.329" "395342716617.832" "467390797903.32"  "614166310997.297" "695075176665.163" "747556154537.287" "853955405511.502" "1055127126230.98" "928042998085.702" "1147589183475.73"
    "AUT" "197508773215.323" "214394866675.24"  "262273631180.054" "301457562038.541" "316092273276.015" "336280064332.411" "389185571506.052" "432051935642.945" "401758735822.211" "392275107258.667"
    "AZE" "5707720390.8515"  "6235856819.58445" "7276753894.71541" "8680370408.05943" "13245716099.0057" "20982986344.3027" "33050343782.7759" "48852482960.0779" "44291490420.5026" "52909294791.9262"
    "BHS" "8317830000"       "8881160000"       "8870090000"       "9055290000"       "9836200000"       "10167250000"      "10618340000"      "10526000000"      "9981960000"       "10095760000"     
    "BHR" "8976196808.51064" "9593510638.29787" "11074813829.7872" "13150159574.4681" "15968723404.2553" "18504760638.2979" "21730000000"      "25710904255.3191" "22938218085.1064" "25713271276.5957"
    "BGD" "53991289844.3291" "54724081490.5102" "60158929188.2556" "65108544250.0425" "69442943089.4309" "71819083683.7403" "79611888213.148"  "91631278239.3237" "102477791472.39"  "115279077465.226"
    "BRB" "3054500000"       "3106500000"       "3209500000"       "3444500000"       "3819500000"       "4217450802.54938" "4674007452.49163" "4784925079.03312" "4465657314.64407" "4529928302.16747"
    "BLR" "12354820143.8849" "14594249022.8922" "17827791321.3067" "23144351851.8519" "30207567316.6202" "36954312354.3124" "45277399813.6067" "60763483146.0674" "50874078052.2735" "57222490768.7143"
    end
    The above is part of the dataset, I want to 1) count the gdp of yr2001-yr2010 that belong to country "BLX" separately; 2)Destring GDP value: NaN == .
    The following is my code:

    foreach v of varlist yr`*' {
    local yr`*': variable label `v'
    rename `v' yr`*'destring yr`*', replace ignore("NaN")bys countrycode: egen gdp`*' = total(yr`*') if countrycode == "BLX"
    replace yr`*' = gdp`*' if countrycode == "BLX"
    drop gdp`*'
    }
    duplicates drop
    save "GDP.dta", replace

    But it turns out that variable yr not found,
    so why the "yr"cannot be found?

  • #2
    Duplicate post. Please follow statalist.org/forums/forum/general-stata-discussion/general/1677283-variable-not-found

    Comment

    Working...
    X