Hello,

I would like to run the following loop but I get the message:

Code:
femnumlist not found
r(111);
The loop should generate new variables malepop`num' and fempop`num' from the variables fem`num' and male`num' that already exist.

I bet the mistake is easily found but I can't manage to find it. Can someone help, please?
Thank you!!

Code:
foreach num in numlist 6569 7074 7579 80{
 
 *[VARIABLES] Populations of different age groups in levels per country:
 *[NOTE] fem`num' and male`num' are in percentages.

 gen double fempop`num' = (fem`num'/100)*fempop
 label var fempop`num' "Total female population between ages `num' per country" if `num' !=80
 label var fempop`num' "Total female population of age `num' or older per country" if `num' ==80
 
 gen double malepop`num' = (male`num'/100)*malepop
 label var malepop`num' "Total male population between ages `num' per country" if `num' !=80
 label var malepop`num' "Total male population of age `num' or older per country" if `num' ==80
 
 gen double pop`num' = fempop`num'+malepop`num'
 label var pop`num' "Total population between ages `num' per country" if `num' !=80
 label var pop`num' "Total population of age `num' or older per country" if `num' ==80
 
 drop fempop`num' malepop`num'
 
}
Data example:
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double(fem6569 male6569 fem7074 male7074 fem7579 male7579 fem80 male80) long(fempop malepop)
1.30260368908481 1.44714634733362 .797219038662651 .876422266562882 .390845519171214 .423348863079346   .17221127466249  .178390259126154   4346990   4649361
1.99251468530059 1.50848276672718 1.83718999623341 1.45291645938139 1.23188980891158 .941184013525884  1.07467552508689  .823996096110715    780595    828205
1.39305727537935 1.49075384268822  1.0003162626297 .989113834820901 .508354182301885 .511697460394985  .280927337032472  .267585402152509   5527051   5597837
               .                .                .                .                .                .                 .                 .         .         .
               .                .                .                .                .                .                 .                 .         .         .
1.39829690408881 1.18654394555214 .779666275942908  .62667109557509 .415465765703647 .309744048228917    .2183341377646  .134763272778585   2900597   2742585
 1.9197267292912 1.04346491732842 1.51665243381725 .636820501016611 1.03501280956447 .368281735527679  1.06575576430401  .402808148233399     29273     26066
2.36150391990908  2.4328121165007 1.67295899800425 1.60640664081115 .999963835477239 .856650886590692  .745097563900593  .488778064389204  10148066  10471009
1.70617958495217 1.80143765067813 2.26110756994265 1.91217949924751   1.562221647855 1.16057457300712  1.35699405941818  .894683394592033    971118    903002
1.25927266148001 .974673540812103  .81418491043966 .538140217514018 .441469151438393 .293531027734919  .390808757011037   .22579309825763     27637     26574
3.60656645665957 2.88374247639685 2.82305628868401 2.21465712453741 1.81319175563392 1.27838009780804  1.61731912371302  .944664640685968   5085024   5191453
5.14270933690004 3.93973803899661 4.02189162048771 2.91888560307504 2.70365007718777 1.90140331914429  2.05954061167234  1.35495290895732   3764742   3282797
1.79000067907437 1.54372703569845 1.94333370403577 1.46751480503087 1.25584471439018 .926085943781136  1.10915480828943  .667554735946089   2032178   1863218
1.64864013441142 1.34593356242841 1.26360740662956 .945017182130584  .74381322412405 .523100420007637  .633553852077426  .402825505918289     57143     52385
 1.3926616931904 1.38451277569513 1.04018975181205 .885444217014328 .503531344826216 .357627469469423   .26634157976334   .17823877095743     75466     86961
1.25673118493073 1.38049820093838 .707415309150564 .761925757819283 .379326135195842 .410507020828138  .224700612456026  .236108272215228  23287874  24911873
3.60776622867229 1.73885307223151 2.19650911943518 1.16084632559758 1.57128848793881 .835113426574779  1.38536968032948  .671763693830406    127478    103461
3.12109843184694 2.46789992294738 2.91166944470769 1.94136920149327 2.01167334697268 1.25557117988881  1.80396135642731  .902902081015246   4491893   3706107
4.83120936772334 3.88655068598904 3.72848513166812 2.91097207777048 2.65532921109072 2.00308224485511  2.19338064836423  1.48895351557052   4649965   4503524
1.80667310374423  1.7134812924796 1.24879304795623 1.17238193695973 .759575152880592 .699469898598861  .478489432464328  .415722675582342     46603     45461
2.37880853293343 2.15371793220254 1.54011950122592  1.4053504471098 .811315752733798 .814247339949561  .448325680841685  .474559741875466   1274969   1156653
               .                .                .                .                .                .                 .                 .         .         .
1.18842088916902 1.09655481456098 .733514199848365 .657229968983666 .373608104281421 .326857685109524   .18908772025979  .154642345643215    109475    113813
2.06523307914062 1.76996954585502 1.52182975830678 1.31889621760831 .861568969781775 .747908327120804  .483955169226031  .415383169111233   1863811   1829638
1.56779338694611  1.3571815416738 1.20144955317615  .85768615587618 .570206266183482 .419679764306934  .569536867151677  .324065326210806   1643268   1582400
 1.9199591963131  1.2760631193365 1.48204819935516 .921356761814881 .883472685210485 .518663072948741  .573437528462393  .289923460206506    274486    250066
 1.5334923584929 1.26574324855437 1.03926912674357 .785949006897459 .599095656686814 .438063691339343  .382002951884872  .253971411610756  36255477  35952077
               .                .                .                .                .                .                 .                 .         .         .
1.76924049033236 1.65939692774512 1.26374320738026 .948226815854352 .760773410842917 .711170111890764  .513079742196386  .272615209558126     39563     42182
2.96778569315617 2.46133128038247 2.55189908297775 1.91321168871379 1.65944354619758 1.35978361721847  1.24695068827322  .987478845453897   3939341   3928033
1.22430424415913 1.34020454982805 .641250011596985 .738532365764938 .260658050879979 .306592844620976 .0665877790550861 .0804724849602296   2371306   2457982
1.42858728821674 1.18627243221539 .965227925901358 .769805596761061 .560985391482459 .415351498455258  .325905798861238  .219423965617878   1441218   1344888
1.69238937063979 1.26686254067545 1.69425220979295 1.31319832769932 1.25462216964876 .947777461851957  1.11211497443253  .703461493907897    107357     94953
1.33820885087154  1.0194399452676 .854971611425765  .59840802667154 .461641408731972 .290678335815758  .301050764506363  .183398352566001   2866293   2856077
1.77959294713237 1.53098742282474 1.17139976002073 .962595470550482 .643946906676333 .493795912624378  .366238153968207  .244461204753552   2631896   2544372
  2.742868150974 2.63013819570321 2.28903014215651 2.15383342024019 1.53830206024231 1.44731099137277  1.43315066967953  1.13247088620167   8851741   9057268
               .                .                .                .                .                .                 .                 .         .         .
1.98851776579331  1.7566544038087 1.38823273837021 1.17628760008656  .83008675145949 .650562648777321  .476485237594829  .311756113395369    764143    739365
1.80174251624976 1.53455353143657 1.27834911831701 1.02371743871569 .723094725539357  .56694420753594  .422402514477532  .275154740453951   1534787   1466806
5.08864839972369 4.07477341389728 4.26858428239962 2.94939577039275 3.15804389025665 2.06570996978852  2.93487309374945  1.64086102719033     56460     52960
2.21360920612412  1.8998849161099 1.49092040064388 1.20616870718919  .89006174683771  .66006009643872  .732843444300403  .471764944446346   3919393   3797232
2.08468824334522 1.65960135735236 1.31115343565014 .897458268869106 .723904692833102 .374068795899996  .291187314150654  .108045774219175 323230499 343839501
1.50791411664279 1.23591220596452 1.03700970817599  .78599208291078 .631573997714021 .441686897517841  .423894748518213  .275165635640436   8294041   8186342
1.52218728525915 1.28633934957297 1.01513857943069 .829862425848795 .610124315432189 .473305566073457  .389396747391875  .271361857882115     96045     95076
1.50443823403748 1.12393936477422 .957039923452877 .671820881448438 .550449247291227 .361722246027968  .410168935262011  .243921560120431   7964764   7283487
1.71645403940764 1.47909505498029 1.15693212065313 .958341672512188 .661514115299021 .518421650904809  .406629301420428  .281167964340052    522585    514635
 1.3112301750851 1.27210961619875 .925188136343515 .849498988832164 .542504312252904 .480286283666874    .3576498603288  .308734395489793    655110    677930
1.26873941377429 1.10045935470239 .780753882812276 .644351169736735 .399448798553096 .310014900964711  .212040306605805  .147468926976469   1741653   1817335
3.14889161052714 2.32616931790865 2.37059382547059 1.57246761193526 1.43614089846795 .986095134787195  1.20968611577506  .709597118500285   2151882   1988118
1.65204310852774 1.93269871202756  1.3949689157533 1.61625602666396 .755618899176183 .891548828654988  .508479525968817  .537363260853477   3492766   3648369
2.10212107332944 1.46485602917138 1.47985533111171 .930466490632465 1.08027859816479 .630265308688545  1.37087985848982  .685275996479316     62262     62564
1.80625270371413 2.10107006170429 2.12657845405918 1.99882129898532 1.22877369826894 1.13609736354406  .743650134241552  .665682048951595    291265    281665
 4.2547711074133  3.2141775044242 3.14070418058252 2.20125968225541 2.04248986224672 1.38233541479176  1.45716121798372  .931606496929275   4932704   4669302
4.15113663983003 3.68963314409205 3.21636730161605 2.78221648123836 2.20712315378073 1.89451000820085  1.76720621550558  1.48574354931243   2307409   2272194
1.20301466917097 1.02951434825488 .748912294049119 .615784283068338 .387532393428592 .303081326822697  .206842443118328  .137108219276935     42062     41574
               .                .                .                .                .                .                 .                 .         .         .
1.09751988055678  1.1882498886278 .732930269854115 .764885650884292 .420486381849353 .417608258870353  .280529229891306  .250085290416115   1626212   1667830
1.99951342973525 1.75947581842864 1.53370818894236 1.25373213142383 .999888695952096 .748604507380654  .653130393352025  .445941575228988   2273054   2272496
1.94837213921371 1.54765774485202 1.34261442713564 .976223323133108 .768376023016976 .500697098658199  .438410378987588  .240914956157559  13321995  13674538
1.49162761552263 1.31918196618623 1.07861091643031 .871009647123964 .671089687500446 .487092740019666  .480817954343348  .283972203475961   1401150   1361749
2.28349419144803 2.08674795122926 1.59783167868304 1.38077153707775 .895277144326968  .77393563861683  .513671020201322  .379772136717969    130244    125079
1.37559936219755 1.09252555274276 .941199563608847 .729070366882378 .520881487371255 .379583149733745  .297423044809747  .184751586156447    703042    694449
4.64542101151056 2.88039643845766 3.74744164899792 2.16053002421893 2.57975948925677 1.32133742132569  2.14643993779032   .92947840866148    676686    534851
1.38614411013656 1.11878927003585 .945375818807594 .689851025310315 .525702231597646 .361491403485937  .283113134228933  .166250547266036    180146    169028
 1.3735387317654 1.02889983370857 .914600375889974 .652759702074056 .520165443291832 .337123857597865  .284314142622401  .163884698554781  11140491  11010787
               .                .                .                .                .                .                 .                 .         .         .
.538350247420951 .965425335011476 .556172943051245 .824757533130969 .325526293718024 .482712667505738  .244275769521094  .308975592902446    190774    202612
3.35316076665302 2.44147035056458 2.61816957393133 1.65778215162885 1.67079442128851 .951062911355543  1.22906014659801  .617249848543442   2296097   2133537
4.74340930195537 3.20751848968217 3.95168714016609 2.56587583140309 2.89490010877928 1.69327211846342  2.61309702581518  1.35862423523063  24044207  22770030
.959687837802209 1.40718786580658 .959687837802209 1.22786481034096  .33483614121121 .405967472790217  .150280787787709  .166870065502727     37927     40149
3.16146603742575 2.76434710513138  2.2446056678641 1.87737545046339 1.33400640197851 1.04170942135463  .847205591165583  .559436541097858    255546    243638
1.26512533567279 1.03598028598581 .714675453893804 .565230844033859  .30437899196525 .231507061241629   .10056810279344 .0718279664950162    186939    180989
2.72954059180222 2.75582643997354 2.96125349204421 2.62573407921762 2.06855151407562 1.50021289301523   1.5783105513459  .960776805105148   1947169   1698431
4.96043387550626 3.75285481954108 3.73768140468285  2.8955793509131 2.36841640217188 1.89277936739686  1.74964044106439  1.38895865327116  38951020  33863880
1.25861144745665 1.09044262935749 .763638497379968 .658484279124202 .384676742567001 .316905543983217  .178142586193934  .137862195198076   3272099   3380188
               .                .                .                .                .                .                 .                 .         .         .
3.05650098397539 2.39834661418449 2.32331541491891 1.69711274049192 1.53883839446138 1.09630528447164  1.16364960848474   .78146155951967   4247634   4084091
               .                .                .                .                .                .                 .                 .         .         .
2.05941580684673 1.52543592449572  1.8248250949781 1.08171635526347 1.01932778342918 .590027102870985  1.03593597541988  .458110474180318     48173     41696
 .92452148790177 .573726404220987 .556157457565908 .299669595061855 .411700975081257 .212586122992598  .274467316720838  .156237994006608     27694     39048
1.20842012093341 1.12035108242754 .816901814963224 .747776301279456 .450157059499815 .403673494468135  .282514683740373  .235093139004682   2078828   2131919
1.59769720044768 1.57790715281749 1.01480521305488 1.02176649663592 .564081881497439 .594617928035636  .232802722375562   .28329668293146   1807536   1769873
1.50322233468718 1.23466935778128 .990403464490256 .776763496389019 .512498558597804  .41352876786178  .238311829747979  .180795566235278    312197    304212
1.55838785529806 1.26931374670977 1.09861612915661 .757887828412241 .732060317004195 .429737409845909  .636741788413893  .330244995706117    285362    286457
1.44860546517257 1.32040996268132 .987900266213445 .857417964511149 .564884511314706  .45893390097505  .454762254275746  .343357184755679   1968719   1897440
1.43606319859209 1.28175166208223 1.04166256550377 .924546991530935 .552672711452678 .469558398025547  .440661750520684   .32552267951417   1015973   1022664
1.80306379219963 .809287155700653 1.19139270787118 .461615514648612 .595427871071844 .202242440823773  .375808888527929  .112737782455437   1494915   1580690
3.90438467032762 3.08965387954891  2.9920292237979 2.28960792563927 1.94999105003811 1.46766335775015  1.26488932845935  .937036715224493   5169965   4814002
3.29814544073123 2.95997384943134 2.29085843876271   1.954529571559 1.55870468647473 1.22073559746159  1.74404549483693  1.08209249636485     86862     88712
1.36083645898312 1.35579480017704 1.02145438954417 .910942376558693 .451397352399636 .391378311600035  .373974328219493  .262127577377651 217551561 231929047
1.62002329799922 1.44394908259517   1.128438096235 1.00618771482447 .682665755467304 .561583496933825  .403997461438917  .318520235724041  44155725  43636790
 1.6872662526495 1.49126311071524 1.27516200794202 1.20331413940366 .722251416221536 .730061337142411  .452838313129461  .471687330449841  10664289  11242614
1.83540350641863 1.53037151866593 .818326268993607 .691398577329676 .450688038260873 .372795043726849  .298637061300915  .231384384444991   3623131   3666630
 3.6489298825113 3.45881621947963 3.33579779880693  3.0559991771768 2.44794856420527 2.13370454306895  2.37344423190311  1.85381785033212   1405831   1422769
               .                .                .                .                .                .                 .                 .         .         .
1.92748045291957 1.87339574211083 1.51125261477085 1.22933338366299 .856722691114875 .679639136343047   .70694667566164  .550543560320096   1042102   1071918
3.89232498427785 3.09852561905975 3.10737619115879 2.42325796638648 2.04456048089382 1.62458277783961  1.55559440370564  1.18118936693988  25781724  24417976
1.72292112692067 1.28587249983413 1.53499838957201 1.29697300662968 1.03055550292719 .679937939235571  .704207006309089  .330208179159628    844500    783752
2.36658337699158 2.19988495544686 1.80538144409702 1.47419078488488 1.19239090802117 .799395468481673  .906114492611604  .477148834829607  46968886  45531686
1.78453032465416 1.72352231406315 1.34918583613337 1.26837616659416 .811579219436547 .746948591878781    .4542236506456  .400356237020742    444938    487319
end