I am trying to code used to replace values of one variable with other values from different variable.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(pre1 pre2 pre3 pre4 pre5 pre6 pre7 pre8 pre9 pre10 pre11 pre12 pre13 pre14 pre15 pre16 pre17 pre18 pre19 pre20 pre21 crv5_ crv7_ crv8_ crv9_ crv10_ crv11_ crv12_ crv13_ crv14_ crv15_ crv16_ crv17_ crv18_ crv19_) . . . . . . . . . . . . . . . . . . . . . 1.420813e-10 1.538471e-06 .0030466826 .00641038 .009309801 .026179815 .08466652 .08571296 .17514174 .24400574 .15538634 .17509454 .03229719 .002746747 . . . . . . . . . . . . . . . . . . . . . .00006437384 .014297502 .38144755 .1563745 .1026714 .12815352 .12850326 .04299963 .031593457 .011509055 .0018745286 .0005022692 8.872414e-06 7.404656e-08 . . . . . . . . . . . . . . . . . . . . . 4.663782e-18 1.9553883e-12 2.6198393e-07 1.6389433e-06 4.763092e-06 .000029164466 .0002974402 .0007629592 .00424578 .021396916 .04420042 .25058898 .37056875 .3079029 . . . . . . . . . . . . . . . . . . . . . 1.0865772e-20 1.3506045e-14 6.395264e-09 5.36199e-08 1.901735e-07 1.473112e-06 .000021332846 .00007103983 .000537118 .0039952984 .011536729 .11203518 .30441836 .5673832 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5554887e-13 8.119904e-09 .00009769932 .0003373321 .000663544 .0026016266 .013705858 .02092475 .065428406 .1577846 .16845314 .3664564 .1671602 .03638645 . . . . . . . . . . . . . . . . . . . . . 4.432053e-06 .002538139 .18728225 .1246691 .10005043 .15218854 .2023386 .08995057 .08459818 .04274843 .00983818 .003674394 .00011702513 1.737149e-06 . . . . . . . . . . . . . . . . . . . . . 1.930359e-08 .00005772203 .026592746 .035485834 .0399411 .08576635 .1873456 .13358808 .1938521 .17308015 .07124478 .04866727 .004210783 .00016747718 . . . . . . . . . . . . . . . . . . . . . .00013831006 .022900587 .4484086 .155492 .09581362 .11245997 .10333547 .031590864 .02150091 .007073301 .0010327316 .0002499707 3.667307e-06 2.5542525e-08 . . . . . . . . . . . . . . . . . . . . . 3.416533e-12 8.96909e-08 .00048944965 .001369852 .00236238 .008006947 .034042504 .04352798 .11290028 .2140593 .182728 .2962125 .09118113 .0131196 . . . . . . . . . . . . . . . . . . . . . 2.7831446e-12 7.65663e-08 .0004409111 .001252145 .0021789365 .007458689 .03217628 .0416462 .10939837 .21083854 .18276106 .3021616 .09554887 .01413835 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .02444949 .34704915 .5731633 .03207296 .011287073 .007854286 .003458914 .0004719603 .00016830266 .000023152586 1.2896116e-06 1.3433531e-07 3.891738e-10 5.62472e-13 . . . . . . . . . . . . . . . . . . . . . .00007738412 .016031174 .3973496 .15668233 .10134303 .124666 .1224445 .04010816 .02893927 .010290721 .0016333666 .0004272129 7.222545e-06 5.77539e-08 . . . . . . . . . . . . . . . . . . . . . 6.225233e-06 .003180121 .20724833 .13064294 .10236664 .1520457 .19537337 .08397492 .07665811 .03724017 .008224747 .002949925 .00008756543 1.213253e-06 . . . . . . . . . . . . . . . . . . . . . 5.711757e-06 .003003969 .202052 .12915957 .10182344 .15215944 .197224 .0855025 .07864742 .03859181 .0086132325 .003121239 .00009432836 1.3301212e-06 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.479014e-13 2.766093e-08 .0002238192 .0006963295 .0012825185 .004673998 .022109233 .03089581 .08794674 .1879665 .1794586 .3364218 .12604964 .02227501 . . . . . . . . . . . . . . . . . . . . . 1.9768643e-07 .0003020521 .06566214 .06728765 .06611959 .12340982 .22013944 .12998039 .15804556 .11196984 .0365051 .0194239 .0011243086 .0000300288 . . . . . . . . . . . . . . . . . . . . . 1.7802686e-09 .0000101362 .009663225 .016311053 .02087387 .05128955 .13624771 .11598107 .1996272 .22261417 .11418645 .09981927 .012640782 .000735507 . . . . . . . . . . . . . . . . . . . . . .000015732547 .005835186 .26908162 .14480214 .10606255 .14735782 .17211884 .06725853 .05648119 .0245689 .004831323 .001548042 .0000376888 4.3016075e-07 . . . . . . . . . . . . . . . . . . . . . 1.2309873e-15 1.7600225e-10 6.778836e-06 .00003140686 .00007472478 .0003631671 .0026281385 .005173804 .02133938 .07338617 .10815435 .36927125 .2982127 .12135816 . . . . . . . . . . . . . . . . . . . . . 1.4699221e-08 .00004741121 .02378473 .032655656 .03731798 .08141199 .18195927 .132503 .1961638 .1797775 .07595441 .05339102 .00483218 .0002009945 . . . . . . . . . . . . . . . . . . . . . .00009772538 .018516937 .4177502 .15660757 .09936238 .11996747 .1147443 .03656965 .02577977 .008887726 .00136464 .000346068 5.530052e-06 4.185778e-08 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.200096e-08 .00006342677 .028044706 .036909204 .04123942 .0878805 .1898518 .13400628 .1925908 .16980077 .06902045 .04650248 .0039369157 .0001532351 . . . . . . . . . . . . . . . . . . . . . 8.74527e-11 1.0668475e-06 .002420652 .005298589 .007876478 .0227117 .0761929 .0796256 .16798724 .2439256 .1616388 .19109465 .03777904 .003447664 . . . . . . . . . . . . . . . . . . . . . 9.86672e-15 9.2322e-10 .000021780725 .00008932268 .0001962402 .0008711708 .005513462 .00976045 .0358137 .10604044 .13655724 .3845895 .24438936 .07615732 . . . . . . . . . . . . . . . . . . . . . .0004772772 .04777861 .5547145 .14125688 .07795527 .082321 .06512605 .01700824 .01015191 .0028022644 .0003383679 .00006887862 7.32511e-07 3.731328e-09 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.382776e-09 8.4100875e-06 .008640654 .014927684 .01935464 .04821897 .1306954 .11326978 .1984135 .22636737 .11873664 .1064987 .014020106 .0008481631 . . . . . . . . . . . . . . . . . . . . . 7.371245e-15 7.325238e-10 .00001852672 .00007731687 .0001718025 .0007725425 .004983033 .008956077 .03341133 .10104962 .13265586 .3838606 .25238574 .08165754 . . . . . . . . . . . . . . . . . . . . . 3.533416e-11 5.367582e-07 .0015648413 .003680154 .00570938 .017241038 .06188371 .068546295 .15338926 .24036573 .17132632 .22141483 .04971202 .005165862 . . . . . . . . . . . . . . . . . . . . . 4.013545e-08 .00009764305 .035684004 .0440068 .04751841 .09773317 .2005741 .13502589 .185556 .1543016 .05914929 .03739148 .002860873 .00010070638 . . . . . . . . . . . . . . . . . . . . . .146914 .57610166 .27103055 .004148152 .0010629876 .0005582546 .00016618687 .000014277997 3.603853e-06 3.083858e-07 9.980185e-09 6.657469e-10 7.81153e-13 4.71743e-16 . . . . . . . . . . . . . . . . . . . . . 6.792519e-06 .003368762 .21260795 .13212207 .10288516 .15187594 .19344084 .0824197 .07465997 .03590137 .0078447955 .002784368 .0000811558 1.1045282e-06 . . . . . . . . . . . . . . . . . . . . . .00023336885 .031381764 .4944887 .15145 .08918554 .10020955 .08655431 .024802873 .01598968 .004892774 .0006606823 .0001488482 1.9128208e-06 1.1711734e-08 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.87591e-08 .0001852767 .05062721 .05637298 .05775486 .11251378 .2134942 .1336015 .1714527 .13036391 .04566101 .026204644 .001716061 .00005177949 . . . . . . . . . . . . . . . . . . . . . 2.4211585e-07 .0003481099 .070727564 .07068649 .06860321 .12643145 .2214434 .12850748 .1537795 .10669007 .03405015 .017718185 .0009886513 .00002546704 . . . . . . . . . . . . . . . . . . . . . 4.1207915e-07 .0005041448 .08563372 .08000084 .07512136 .1338603 .2233571 .12377687 .14197627 .0931756 .028096253 .013783229 .0006975926 .000016321488 . . . . . . . . . . . . . . . . . . . . . .00005279573 .012630104 .3645571 .15569603 .1038698 .13167919 .13498788 .04620522 .034612022 .0129374 .0021658828 .0005954956 .000011022436 9.627696e-08 . . . . . . . . . . . . . . . . . . . . . 4.195276e-09 .000019035517 .014034597 .02184544 .02672476 .06261673 .15522756 .12419013 .2012488 .2074922 .09852562 .07889093 .008739511 .0004447356 . . . . . . . . . . . . . . . . . . . . . 1.2491035e-09 7.800611e-06 .008258502 .014400246 .01876863 .04701891 .12847514 .11214804 .1978358 .2277815 .12055216 .10924847 .014607187 .000897576 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .00009748842 .018489296 .4175369 .1566111 .09938468 .12001785 .11482436 .03660569 .025811456 .008901535 .0013672354 .0003468383 5.545634e-06 4.199988e-08 . . . . . . . . . . . . . . . . . . . . . .0008490111 .06635578 .5977817 .12933302 .06755557 .06771101 .04976092 .0120105 .006719737 .0017007086 .00018679987 .000034930843 3.16538e-07 1.3803058e-09 . . . . . . . . . . . . . . . . . . . . . .0014281237 .08849718 .6297351 .1161102 .0575724 .05494088 .03767611 .00843862 .0044429223 .0010362626 .0001040617 .000017972205 1.4000278e-07 5.2717725e-10 . . . . . . . . . . . . . . . . . . . . . .14222886 .5738478 .2776126 .0043824874 .0011311137 .0005977574 .00017949633 .000015583995 3.9637544e-06 3.4279574e-07 1.1230338e-08 7.565779e-10 9.05942e-13 5.579114e-16 . . . . . . . . . . . . . . . . . . . . . 8.137403e-09 .00003087388 .018598389 .0271215 .03201694 .072259806 .16965553 .12921666 .19969645 .19355987 .0864612 .06464544 .00644237 .0002949633 . . . . . . . . . . . . . . . . . . . . . .24860124 .58354634 .1658999 .001435535 .0003231849 .00015172327 .00003866506 2.748065e-06 6.045692e-07 4.27598e-08 1.1096662e-09 6.200218e-11 5.051515e-14 2.141888e-17 . . . . . . . . . . . . . . . . . . . . . .0003257327 .03823438 .52318805 .14736404 .08423046 .091977 .0762949 .020951144 .01303596 .0038042134 .0004879763 .0001049153 1.2359287e-06 6.953635e-09 . . . . . . . . . . . . . . . . . . . . . .2622057 .58035177 .15573716 .0012608147 .00027966892 .00012963015 .00003245663 2.257163e-06 4.888744e-07 3.3834052e-08 8.561264e-10 4.688139e-11 3.663736e-14 1.4919074e-17 . . . . . . . . . . . . . . . . . . . . . .07042101 .49665 .4147084 .01178584 .0034969284 .0020889633 .000743706 .00007915235 .00002339871 2.4896146e-06 1.035096e-07 8.4647676e-09 1.5058954e-11 1.3589284e-14 . . . . . . . . . . . . . . . . . . . . . .018322403 .3087128 .6028496 .03939577 .014445047 .010432255 .004838905 .0007008064 .00026160083 .00003830219 2.289172e-06 2.5296734e-07 8.244482e-10 1.3352442e-12 . . . . . . . . . . . . . . . . . . . . . .1256432 .56382877 .3027121 .005360195 .001420921 .0007686496 .0002384135 .00002152403 5.633588e-06 5.0686475e-07 1.738065e-08 1.2149368e-09 1.5691892e-12 1.0396132e-15 . . . . . . . . . . . . . . . . . . . . . .03809432 .4095334 .51575696 .02223603 .007316635 .00479273 .0019399498 .00024005736 .0000794721 9.876368e-06 4.9022987e-07 4.639294e-08 1.1087609e-10 1.3306054e-13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . end
Code:
forvalues j = 1/21{ replace pre`j'=crv`j'_ if pre`j'==. }
I could simply make commands such as "replace pre5=crv5_ if pre5==.". However, I need to run the above cods every quarter and each quarter gives "crv`j'_" with different "j".
Could you please help me to write codes that replace values only if "crv`j'_" exists?
Thanks in advance.
0 Response to Replace the value of one variable with the value of different variable
Post a Comment