Quantcast
Channel: Statalist
Viewing all 73191 articles
Browse latest View live

How to transform a panel dataset variables in logarithmic (ln)

$
0
0

Dear statalist-users.
Please i need a help with my panel data. I have a dateset for 43 countries, from 2002 to 2013. I also have these 5 variables ( distw, repórter_pib, dest_pib, total_export, xrate).I want to know how to transform these variable in logarithmic (ln). Sorry for my bad English, I am still learning how to write in this language. Thank You.
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str3 id int year byte(clang cfront) float(distw reporter_pib dest_pib) double total_export float xrate
"DZA" 2002 0 0  5194.24  12497345536   56760287232      214862 43.53
"DZA" 2003 0 0  5194.24  14188949504   67863834624       27555 74.61
"DZA" 2004 0 0  5194.24  19640862720    8.5325e+10       32404 83.54
"DZA" 2005 0 0  5194.24  2.82337e+10  103198220288       36990 87.16
"DZA" 2006 0 0  5194.24  41789493248  117027274752      172230 80.37
"DZA" 2007 0 0  5194.24  60448886784  134977085440      112234 76.71
"DZA" 2008 0 0  5194.24  84178083840  1.710007e+11      176568 75.03
"DZA" 2009 0 0  5194.24  75492417536   1.37211e+11       45515 79.33
"DZA" 2010 0 0  5194.24  8.24709e+10  1.612073e+11     3845443 91.91
"DZA" 2011 0 0  5194.24 104115871744  199070859264       40668 93.93
"DZA" 2012 0 0  5194.24 115341615104   2.04331e+11      121019 95.47
"DZA" 2013 0 0  5194.24 124163178496  2.101834e+11      183382 96.52
"AUS" 2002 0 0  13528.2  12497345536  3.942507e+11       47392 43.53
"AUS" 2003 0 0  13528.2  14188949504  4.664514e+11       32002 74.61
"AUS" 2004 0 0  13528.2  19640862720  6.128717e+11        3295 83.54
"AUS" 2005 0 0  13528.2  2.82337e+10  6.933386e+11       36013 87.16
"AUS" 2006 0 0  13528.2  41789493248  7.472058e+11       40161 80.37
"AUS" 2007 0 0  13528.2  60448886784  8.534412e+11       32597 76.71
"AUS" 2008 0 0  13528.2  84178083840 1.0550316e+12      138837 75.03
"AUS" 2009 0 0  13528.2  75492417536  9.262833e+11       22377 79.33
"AUS" 2010 0 0  13528.2  8.24709e+10 1.1412678e+12       87135 91.91
"AUS" 2011 0 0  13528.2 104115871744 1.3880664e+12     2370492 93.93
"AUS" 2012 0 0  13528.2 115341615104  1.534426e+12       31710 95.47
"AUS" 2013 0 0  13528.2 124163178496 1.5603724e+12    32726257 96.52
"AUT" 2002 0 0  6357.02  12497345536  212970733568     2395183 43.53
"AUT" 2003 0 0  6357.02  14188949504  260721442816        4301 74.61
"AUT" 2004 0 0  6357.02  19640862720  2.998572e+11       23564 83.54
"AUT" 2005 0 0  6357.02  2.82337e+10  314649051136       60267 87.16
"AUT" 2006 0 0  6357.02  41789493248  3.343094e+11       28877 80.37
"AUT" 2007 0 0  6357.02  60448886784  3.864589e+11       81663 76.71
"AUT" 2008 0 0  6357.02  84178083840  4.276116e+11      312407 75.03
"AUT" 2009 0 0  6357.02  75492417536  3.975943e+11      137279 79.33
"AUT" 2010 0 0  6357.02  8.24709e+10  389679349760       51545 91.91
"AUT" 2011 0 0  6357.02 104115871744  4.290728e+11      107636 93.93
"AUT" 2012 0 0  6357.02 115341615104  4.075751e+11       54534 95.47
"AUT" 2013 0 0  6357.02 124163178496  4.283219e+11      187263 96.52
"BEL" 2002 0 0  6696.23  12497345536  2.583898e+11   496271262 43.53
"BEL" 2003 0 0  6696.23  14188949504  318573379584   258104931 74.61
"BEL" 2004 0 0  6696.23  19640862720  3.704457e+11   118705977 83.54
"BEL" 2005 0 0  6696.23  2.82337e+10  3.869544e+11   520731531 87.16
"BEL" 2006 0 0  6696.23  41789493248  4.106988e+11   361139339 80.37
"BEL" 2007 0 0  6696.23  60448886784  4.723091e+11   285131429 76.71
"BEL" 2008 0 0  6696.23  84178083840  5.200908e+11   194715997 75.03
"BEL" 2009 0 0  6696.23  75492417536  4.858336e+11   249866605 79.33
"BEL" 2010 0 0  6696.23  8.24709e+10  4.844331e+11    93505315 91.91
"BEL" 2011 0 0  6696.23 104115871744  5.280998e+11   247876457 93.93
"BEL" 2012 0 0  6696.23 115341615104  4.987462e+11   595916748 95.47
"BEL" 2013 0 0  6696.23 124163178496  5.247788e+11   583584715 96.52
"BRA" 2002 1 0  6559.97  12497345536  5.087799e+11    11629324 43.53
"BRA" 2003 1 0  6559.97  14188949504  559008448512     7551779 74.61
"BRA" 2004 1 0  6559.97  19640862720  6.696427e+11     3580646 83.54
"BRA" 2005 1 0  6559.97  2.82337e+10  8.921068e+11      120231 87.16
"BRA" 2006 1 0  6559.97  41789493248 1.1077886e+12   464424200 80.37
"BRA" 2007 1 0  6559.97  60448886784  1.395968e+12   944789813 76.71
"BRA" 2008 1 0  6559.97  84178083840  1.694616e+12  2240263807 75.03
"BRA" 2009 1 0  6559.97  75492417536  1.664563e+12   137760201 79.33
"BRA" 2010 1 0  6559.97  8.24709e+10 2.2093997e+12   500753093 91.91
"BRA" 2011 1 0  6559.97 104115871744   2.61519e+12   438078678 93.93
"BRA" 2012 1 0  6559.97 115341615104 2.4131742e+12    45921774 95.47
"BRA" 2013 1 0  6559.97 124163178496 2.3920944e+12   726835843 96.52
"CAN" 2002 0 0 10904.94  12497345536  7.525317e+11       25695 43.53
"CAN" 2003 0 0 10904.94  14188949504  8.877518e+11       34240 74.61
"CAN" 2004 0 0 10904.94  19640862720 1.0184013e+12       37661 83.54
"CAN" 2005 0 0 10904.94  2.82337e+10 1.1641443e+12   274661091 87.16
"CAN" 2006 0 0 10904.94  41789493248 1.3107528e+12   534404069 80.37
"CAN" 2007 0 0 10904.94  60448886784 1.4578717e+12  1117813799 76.71
"CAN" 2008 0 0 10904.94  84178083840 1.5426186e+12  2607324781 75.03
"CAN" 2009 0 0 10904.94  75492417536   1.37084e+12  1207221890 79.33
"CAN" 2010 0 0 10904.94  8.24709e+10 1.6140138e+12  1575913884 91.91
"CAN" 2011 0 0 10904.94 104115871744 1.7887963e+12  2469608910 93.93
"CAN" 2012 0 0 10904.94 115341615104 1.8327156e+12  1930696671 95.47
"CAN" 2013 0 0 10904.94 124163178496  1.838964e+12  1507322782 96.52
"CHL" 2002 0 0   8914.1  12497345536   70984564736           0 43.53
"CHL" 2003 0 0   8914.1  14188949504   77840187392    64495999 74.61
"CHL" 2004 0 0   8914.1  19640862720  1.006307e+11   430833024 83.54
"CHL" 2005 0 0   8914.1  2.82337e+10  124404146176  1197146448 87.16
"CHL" 2006 0 0   8914.1  41789493248   1.54671e+11  1317205508 80.37
"CHL" 2007 0 0   8914.1  60448886784  1.730813e+11   962541529 76.71
"CHL" 2008 0 0   8914.1  84178083840  179626672128  1671247631 75.03
"CHL" 2009 0 0   8914.1  75492417536  171956961280    42462874 79.33
"CHL" 2010 0 0   8914.1  8.24709e+10  217538265088      164065 91.91
"CHL" 2011 0 0   8914.1 104115871744  250832355328      345366 93.93
"CHL" 2012 0 0   8914.1 115341615104  2.652316e+11         286 95.47
"CHL" 2013 0 0   8914.1 124163178496  2.766737e+11        9025 96.52
"CHN" 2002 0 0 11769.51  12497345536  1.461914e+12  1087049343 43.53
"CHN" 2003 0 0 11769.51  14188949504 1.6499214e+12  2205934880 74.61
"CHN" 2004 0 0 11769.51  19640862720 1.9417456e+12  4717339146 83.54
"CHN" 2005 0 0 11769.51  2.82337e+10 2.2685942e+12  6581828714 87.16
"CHN" 2006 0 0 11769.51  41789493248  2.729784e+12 10933295107 80.37
"CHN" 2007 0 0 11769.51  60448886784  3.523094e+12 12888664603 76.71
"CHN" 2008 0 0 11769.51  84178083840  4.558431e+12 22382523829 75.03
"CHN" 2009 0 0 11769.51  75492417536 5.0594196e+12 14675830702 79.33
"CHN" 2010 0 0 11769.51  8.24709e+10  6.039658e+12 22815049454 91.91
"CHN" 2011 0 0 11769.51 104115871744  7.492432e+12 24922180492 93.93
"CHN" 2012 0 0 11769.51 115341615104  8.461623e+12 33561896917 95.47
"CHN" 2013 0 0 11769.51 124163178496  9.490603e+12 31972669347 96.52
"COL" 2002 0 0  9911.52  12497345536   9.79334e+10       12669 43.53
"COL" 2003 0 0  9911.52  14188949504   94684585984       22999 74.61
"COL" 2004 0 0  9911.52  19640862720  117074862080       51789 83.54
"COL" 2005 0 0  9911.52  2.82337e+10  146566266880         110 87.16
"COL" 2006 0 0  9911.52  41789493248  162590146560    33528085 80.37
"COL" 2007 0 0  9911.52  60448886784  2.074165e+11       12010 76.71
"COL" 2008 0 0  9911.52  84178083840  243982434304       24426 75.03
"COL" 2009 0 0  9911.52  75492417536  233821667328      165684 79.33
"COL" 2010 0 0  9911.52  8.24709e+10  2.870182e+11       37043 91.91
"COL" 2011 0 0  9911.52 104115871744  3.354151e+11       57621 93.93
"COL" 2012 0 0  9911.52 115341615104  3.696597e+11       65777 95.47
"COL" 2013 0 0  9911.52 124163178496  3.800634e+11          63 96.52
"CRI" 2002 0 0  10980.7  12497345536   16844378112           0 43.53
"CRI" 2003 0 0  10980.7  14188949504   17517535232        1679 74.61
"CRI" 2004 0 0  10980.7  19640862720   18596366336        2230 83.54
"CRI" 2005 0 0  10980.7  2.82337e+10   19964925952       53610 87.16
"CRI" 2006 0 0  10980.7  41789493248   22526464000       39572 80.37
"CRI" 2007 0 0  10980.7  60448886784    2.6322e+10       25863 76.71
"CRI" 2008 0 0  10980.7  84178083840   29837895680        5970 75.03
"CRI" 2009 0 0  10980.7  75492417536   29382694912       10888 79.33
"CRI" 2010 0 0  10980.7  8.24709e+10   36298326016         968 91.91
"CRI" 2011 0 0  10980.7 104115871744   4.12373e+10         244 93.93
"CRI" 2012 0 0  10980.7 115341615104   45300670464     7825290 95.47
"CRI" 2013 0 0  10980.7 124163178496   49236709376        5729 96.52
"CZE" 2002 0 0  6560.24  12497345536   81696653312         100 43.53
"CZE" 2003 0 0  6560.24  14188949504   99300327424        4156 74.61
"CZE" 2004 0 0  6560.24  19640862720  118976020480        1751 83.54
"CZE" 2005 0 0  6560.24  2.82337e+10  135990214656       27691 87.16
"CZE" 2006 0 0  6560.24  41789493248   1.55213e+11         240 80.37
"CZE" 2007 0 0  6560.24  60448886784  188818161664      290517 76.71
"CZE" 2008 0 0  6560.24  84178083840  2.352048e+11        3493 75.03
"CZE" 2009 0 0  6560.24  75492417536  2.057298e+11       12176 79.33
"CZE" 2010 0 0  6560.24  8.24709e+10  207015854080     1630017 91.91
"CZE" 2011 0 0  6560.24 104115871744  227307454464       64356 93.93
"CZE" 2012 0 0  6560.24 115341615104  206751367168      159171 95.47
"CZE" 2013 0 0  6560.24 124163178496  208796024832       29683 96.52
"DNK" 2002 0 0  7179.06  12497345536  178635161600       29498 43.53
"DNK" 2003 0 0  7179.06  14188949504   2.18096e+11      515311 74.61
"DNK" 2004 0 0  7179.06  19640862720  251242840064     1321903 83.54
"DNK" 2005 0 0  7179.06  2.82337e+10  264559525888       13679 87.16
"DNK" 2006 0 0  7179.06  41789493248  2.829611e+11      526069 80.37
"DNK" 2007 0 0  7179.06  60448886784  319500353536     1528880 76.71
"DNK" 2008 0 0  7179.06  84178083840  3.525915e+11       19984 75.03
"DNK" 2009 0 0  7179.06  75492417536  319762366464       75621 79.33
"DNK" 2010 0 0  7179.06  8.24709e+10   3.19811e+11      147300 91.91
"DNK" 2011 0 0  7179.06 104115871744  3.414987e+11     4570998 93.93
"DNK" 2012 0 0  7179.06 115341615104  322276556800    88914662 95.47
"DNK" 2013 0 0  7179.06 124163178496  3.358775e+11      450843 96.52
"FRA" 2002 0 0  6510.32  12497345536 1.5003378e+12   635741273 43.53
"FRA" 2003 0 0  6510.32  14188949504  1.848124e+12   693959478 74.61
"FRA" 2004 0 0  6510.32  19640862720 2.1241122e+12   815351242 83.54
"FRA" 2005 0 0  6510.32  2.82337e+10 2.2036787e+12  1749100644 87.16
"FRA" 2006 0 0  6510.32  41789493248  2.325012e+12  1553209281 80.37
"FRA" 2007 0 0  6510.32  60448886784 2.6631125e+12  2370503388 76.71
"FRA" 2008 0 0  6510.32  84178083840 2.9234655e+12  4010271285 75.03
"FRA" 2009 0 0  6510.32  75492417536 2.6938274e+12  3270520333 79.33
"FRA" 2010 0 0  6510.32  8.24709e+10 2.6469946e+12  2126302876 91.91
"FRA" 2011 0 0  6510.32 104115871744  2.862502e+12  1825618554 93.93
"FRA" 2012 0 0  6510.32 115341615104  2.681416e+12  1199927259 95.47
"FRA" 2013 0 0  6510.32 124163178496  2.810249e+12  1225880863 96.52
"DEU" 2002 0 0  6738.35  12497345536 2.0763034e+12   211271000 43.53
"DEU" 2003 0 0  6738.35  14188949504 2.5023136e+12    59671000 74.61
"DEU" 2004 0 0  6738.35  19640862720 2.8154706e+12     4056000 83.54
"DEU" 2005 0 0  6738.35  2.82337e+10   2.85763e+12    76656000 87.16
"DEU" 2006 0 0  6738.35  41789493248   2.99862e+12    75943000 80.37
"DEU" 2007 0 0  6738.35  60448886784  3.435683e+12   196009000 76.71
"DEU" 2008 0 0  6738.35  84178083840  3.746917e+12   701305000 75.03
"DEU" 2009 0 0  6738.35  75492417536  3.412976e+12      343447 79.33
"DEU" 2010 0 0  6738.35  8.24709e+10  3.412212e+12   301672072 91.91
"DEU" 2011 0 0  6738.35 104115871744 3.7518765e+12  1229729505 93.93
"DEU" 2012 0 0  6738.35 115341615104  3.533242e+12   341170591 95.47
"DEU" 2013 0 0  6738.35 124163178496  3.730261e+12   624144129 96.52
"GHA" 2002 0 0   2192.4  12497345536    6166197248     1001980 43.53
"GHA" 2003 0 0   2192.4  14188949504    7632720896      802460 74.61
"GHA" 2004 0 0   2192.4  19640862720    8881419264     1165504 83.54
"GHA" 2005 0 0   2192.4  2.82337e+10   10731883520        4663 87.16
"GHA" 2006 0 0   2192.4  41789493248   20409257984      103992 80.37
"GHA" 2007 0 0   2192.4  60448886784   24758818816       17073 76.71
"GHA" 2008 0 0   2192.4  84178083840   28526891008        2941 75.03
"GHA" 2009 0 0   2192.4  75492417536   25977847808      491925 79.33
"GHA" 2010 0 0   2192.4  8.24709e+10   32174772224     2132413 91.91
"GHA" 2011 0 0   2192.4 104115871744   39566290944     9365607 93.93
"GHA" 2012 0 0   2192.4 115341615104   41939730432     1198117 95.47
"GHA" 2013 0 0   2192.4 124163178496   48584736768     1730910 96.52
"HKG" 2002 0 0 11504.13  12497345536  166349225984      156380 43.53
"HKG" 2003 0 0 11504.13  14188949504  161384529920      522402 74.61
"HKG" 2004 0 0 11504.13  19640862720  169099771904      451605 83.54
"HKG" 2005 0 0 11504.13  2.82337e+10  1.815693e+11    87884313 87.16
"HKG" 2006 0 0 11504.13  41789493248  193535426560   150229107 80.37
"HKG" 2007 0 0 11504.13  60448886784  211596951552    49819847 76.71
"HKG" 2008 0 0 11504.13  84178083840  219278737408   121658472 75.03
"HKG" 2009 0 0 11504.13  75492417536  2.140478e+11   133600550 79.33
"HKG" 2010 0 0 11504.13  8.24709e+10  228638670848     1150532 91.91
"HKG" 2011 0 0 11504.13 104115871744  2.485136e+11     4477935 93.93
"HKG" 2012 0 0 11504.13 115341615104  2.626289e+11   106796517 95.47
"HKG" 2013 0 0 11504.13 124163178496  275742654464     1356775 96.52
"IDN" 2002 0 0 10294.87  12497345536  1.956606e+11        1928 43.53
"IDN" 2003 0 0 10294.87  14188949504  234772463616    94802100 74.61
"IDN" 2004 0 0 10294.87  19640862720  2.568369e+11   332731460 83.54
"IDN" 2005 0 0 10294.87  2.82337e+10  285868621824     1142548 87.16
"IDN" 2006 0 0 10294.87  41789493248  3.645705e+11      408000 80.37
"IDN" 2007 0 0 10294.87  60448886784  4.322167e+11     1061636 76.71
"IDN" 2008 0 0 10294.87  84178083840  5.102286e+11      948752 75.03
"IDN" 2009 0 0 10294.87  75492417536  5.395801e+11     2276007 79.33
"IDN" 2010 0 0 10294.87  8.24709e+10  7.550941e+11     3381224 91.91
"IDN" 2011 0 0 10294.87 104115871744   8.92969e+11    19745682 93.93
"IDN" 2012 0 0 10294.87 115341615104  9.178699e+11   503458931 95.47
"IDN" 2013 0 0 10294.87 124163178496  9.104787e+11   212725284 96.52
"IND" 2002 0 0  8025.97  12497345536  5.239686e+11     7162016 43.53
"IND" 2003 0 0  8025.97  14188949504  6.183565e+11           0 74.61
"IND" 2004 0 0  8025.97  19640862720  7.215856e+11      660762 83.54
"IND" 2005 0 0  8025.97  2.82337e+10   8.34215e+11     2830007 87.16
"IND" 2006 0 0  8025.97  41789493248  9.491168e+11   183066968 80.37
"IND" 2007 0 0  8025.97  60448886784 1.2386992e+12   920236282 76.71
"IND" 2008 0 0  8025.97  84178083840  1.224097e+12  1289284732 75.03
"IND" 2009 0 0  8025.97  75492417536 1.3653715e+12  3394217299 79.33
"IND" 2010 0 0  8025.97  8.24709e+10  1.708459e+12  4838456716 91.91
"IND" 2011 0 0  8025.97 104115871744 1.8358145e+12  6005484849 93.93
"IND" 2012 0 0  8025.97 115341615104 1.8317815e+12           0 95.47
"IND" 2013 0 0  8025.97 124163178496 1.8618016e+12  6798300153 96.52
"IRL" 2002 0 0  7160.81  12497345536  1.272154e+11       56018 43.53
"IRL" 2003 0 0  7160.81  14188949504  163476078592       24678 74.61
"IRL" 2004 0 0  7160.81  19640862720  193034764288       13833 83.54
"IRL" 2005 0 0  7160.81  2.82337e+10   2.10363e+11       18765 87.16
"IRL" 2006 0 0  7160.81  41789493248  2.305347e+11       39620 80.37
"IRL" 2007 0 0  7160.81  60448886784  269297156096       24662 76.71
"IRL" 2008 0 0  7160.81  84178083840  2.737223e+11       32412 75.03
"IRL" 2009 0 0  7160.81  75492417536  233556541440       15853 79.33
"IRL" 2010 0 0  7160.81  8.24709e+10  2.184482e+11       25073 91.91
"IRL" 2011 0 0  7160.81 104115871744  237756874752       13465 93.93
"IRL" 2012 0 0  7160.81 115341615104   2.21966e+11   160662432 95.47
"IRL" 2013 0 0  7160.81 124163178496  232077361152   165959520 96.52
"ISR" 2002 0 0  5096.15  12497345536  119876313088      213000 43.53
"ISR" 2003 0 0  5096.15  14188949504  125467164672      106000 74.61
"ISR" 2004 0 0  5096.15  19640862720  134020972544      158000 83.54
"ISR" 2005 0 0  5096.15  2.82337e+10   1.41222e+11      172000 87.16
"ISR" 2006 0 0  5096.15  41789493248  152230969344      228000 80.37
"ISR" 2007 0 0  5096.15  60448886784  1.766751e+11      896000 76.71
"ISR" 2008 0 0  5096.15  84178083840  2.139193e+11       91000 75.03
"ISR" 2009 0 0  5096.15  75492417536  2.064768e+11       90000 79.33
"ISR" 2010 0 0  5096.15  8.24709e+10  232909553664     6001000 91.91
"ISR" 2011 0 0  5096.15 104115871744  2.584082e+11      814000 93.93
"ISR" 2012 0 0  5096.15 115341615104  2.572049e+11       36000 95.47
"ISR" 2013 0 0  5096.15 124163178496  2.905506e+11      266000 96.52
"ITA" 2002 0 0  5645.24  12497345536 1.2670433e+12   289331373 43.53
"ITA" 2003 0 0  5645.24  14188949504 1.5703305e+12   202681880 74.61
"ITA" 2004 0 0  5645.24  19640862720  1.799126e+12    35355777 83.54
"ITA" 2005 0 0  5645.24  2.82337e+10 1.8535125e+12    83736622 87.16
"ITA" 2006 0 0  5645.24  41789493248 1.9435302e+12    51660531 80.37
"ITA" 2007 0 0  5645.24  60448886784 2.2040855e+12   195529422 76.71
"ITA" 2008 0 0  5645.24  84178083840 2.3918755e+12   453740257 75.03
"ITA" 2009 0 0  5645.24  75492417536 2.1862394e+12    36798896 79.33
"ITA" 2010 0 0  5645.24  8.24709e+10 2.1267475e+12   348781371 91.91
"ITA" 2011 0 0  5645.24 104115871744  2.278089e+12  2068356894 93.93
"ITA" 2012 0 0  5645.24 115341615104  2.075221e+12   877520110 95.47
"ITA" 2013 0 0  5645.24 124163178496 2.1369482e+12   720623566 96.52
"JPN" 2002 0 0 13861.75  12497345536 3.9808194e+12   394439804 43.53
"JPN" 2003 0 0 13861.75  14188949504  4.302939e+12    83658124 74.61
"JPN" 2004 0 0 13861.75  19640862720 4.6558033e+12     8672139 83.54
"JPN" 2005 0 0 13861.75  2.82337e+10 4.5718674e+12    18152893 87.16
"JPN" 2006 0 0 13861.75  41789493248   4.35675e+12   696921637 80.37
"JPN" 2007 0 0 13861.75  60448886784  4.356348e+12   190436787 76.71
"JPN" 2008 0 0 13861.75  84178083840  4.849185e+12    25540307 75.03
"JPN" 2009 0 0 13861.75  75492417536 5.0351414e+12    24113043 79.33
"JPN" 2010 0 0 13861.75  8.24709e+10  5.495385e+12    89387939 91.91
"JPN" 2011 0 0 13861.75 104115871744  5.905632e+12    26855954 93.93
"JPN" 2012 0 0 13861.75 115341615104  5.954477e+12   383473989 95.47
"JPN" 2013 0 0 13861.75 124163178496  4.919563e+12   385639333 96.52
"KOR" 2002 0 0  12705.4  12497345536  6.090201e+11   177716784 43.53
"KOR" 2003 0 0  12705.4  14188949504  6.805208e+11   267633814 74.61
"KOR" 2004 0 0  12705.4  19640862720  7.648806e+11   137397995 83.54
"KOR" 2005 0 0  12705.4  2.82337e+10  8.981372e+11      681486 87.16
"KOR" 2006 0 0  12705.4  41789493248 1.0117975e+12   218670939 80.37
"KOR" 2007 0 0  12705.4  60448886784 1.1226793e+12   342584832 76.71
"KOR" 2008 0 0  12705.4  84178083840 1.0022191e+12      743442 75.03
"KOR" 2009 0 0  12705.4  75492417536   9.01935e+11   118154628 79.33
"KOR" 2010 0 0  12705.4  8.24709e+10 1.0944994e+12   114382916 91.91
"KOR" 2011 0 0  12705.4 104115871744 1.2024637e+12     2528752 93.93
"KOR" 2012 0 0  12705.4 115341615104 1.2228071e+12   139541894 95.47
"KOR" 2013 0 0  12705.4 124163178496 1.3056049e+12   136179340 96.52
"MYS" 2002 0 0  9900.25  12497345536  100845527040        4321 43.53
"MYS" 2003 0 0  9900.25  14188949504  110202372096        7787 74.61
"MYS" 2004 0 0  9900.25  19640862720  124749733888        2210 83.54
"MYS" 2005 0 0  9900.25  2.82337e+10  143534424064        5240 87.16
"MYS" 2006 0 0  9900.25  41789493248  162691710976       14462 80.37
"MYS" 2007 0 0  9900.25  60448886784  193549254656       11037 76.71
"MYS" 2008 0 0  9900.25  84178083840  2.308122e+11     1536730 75.03
"MYS" 2009 0 0  9900.25  75492417536  202257465344     1616207 79.33
"MYS" 2010 0 0  9900.25  8.24709e+10  2.475335e+11     4926621 91.91
"MYS" 2011 0 0  9900.25 104115871744  2.893265e+11     2416413 93.93
"MYS" 2012 0 0  9900.25 115341615104  304956538880     1190768 95.47
"MYS" 2013 0 0  9900.25 124163178496  313158238208    50125959 96.52
"MEX" 2002 0 0    12686  12497345536  7.415595e+11        1400 43.53
"MEX" 2003 0 0    12686  14188949504  7.132843e+11       49537 74.61
"MEX" 2004 0 0    12686  19640862720  7.702676e+11      153456 83.54
"MEX" 2005 0 0    12686  2.82337e+10  8.663465e+11       142.1 87.16
"MEX" 2006 0 0    12686  41789493248  9.668704e+11      152083 80.37
"MEX" 2007 0 0    12686  60448886784 1.0434713e+12    53320979 76.71
"MEX" 2008 0 0    12686  84178083840 1.1012753e+12    59246511 75.03
"MEX" 2009 0 0    12686  75492417536  8.949487e+11      250800 79.33
"MEX" 2010 0 0    12686  8.24709e+10 1.0511286e+12       36480 91.91
"MEX" 2011 0 0    12686 104115871744 1.1711876e+12    68953083 93.93
"MEX" 2012 0 0    12686 115341615104 1.1866594e+12       85356 95.47
"MEX" 2013 0 0    12686 124163178496 1.2622488e+12       11859 96.52
"MOZ" 2002 1 0  2794.28  12497345536    4201332992        2211 43.53
"MOZ" 2003 1 0  2794.28  14188949504    4666196992      117857 74.61
"MOZ" 2004 1 0  2794.28  19640862720    5697991168       94539 83.54
"MOZ" 2005 1 0  2794.28  2.82337e+10    6578515456       17519 87.16
"MOZ" 2006 1 0  2794.28  41789493248    7095918080       31775 80.37
"MOZ" 2007 1 0  2794.28  60448886784    9115529216      154746 76.71
"MOZ" 2008 1 0  2794.28  84178083840   11050262528     2987978 75.03
"MOZ" 2009 1 0  2794.28  75492417536   10718503936       92197 79.33
"MOZ" 2010 1 0  2794.28  8.24709e+10   10119169024      231080 91.91
"MOZ" 2011 1 0  2794.28 104115871744   13197133824    12598000 93.93
"MOZ" 2012 1 0  2794.28 115341615104   14934374400     3488500 95.47
"MOZ" 2013 1 0  2794.28 124163178496   15457197056     3367350 96.52
"NAM" 2002 0 1  1582.88  12497345536    3361236224     5550813 43.53
"NAM" 2003 0 1  1582.88  14188949504    4931279872     4511291 74.61
"NAM" 2004 0 1  1582.88  19640862720    6606866432     3834103 83.54
"NAM" 2005 0 1  1582.88  2.82337e+10    7261301248     3546401 87.16
"NAM" 2006 0 1  1582.88  41789493248    7978734592     1320095 80.37
"NAM" 2007 0 1  1582.88  60448886784    8740726784     2238853 76.71
"NAM" 2008 0 1  1582.88  84178083840    8462019584     4744994 75.03
"NAM" 2009 0 1  1582.88  75492417536    8875244544    12048378 79.33
"NAM" 2010 0 1  1582.88  8.24709e+10   11273248768     6183971 91.91
"NAM" 2011 0 1  1582.88 104115871744   12411220992     9274376 93.93
"NAM" 2012 0 1  1582.88 115341615104   13020182528     3842157 95.47
"NAM" 2013 0 1  1582.88 124163178496   12932205568     3777220 96.52
"NLD" 2002 0 0  6856.13  12497345536  4.644786e+11    28001211 43.53
"NLD" 2003 0 0  6856.13  14188949504  5.709176e+11    21261447 74.61
"NLD" 2004 0 0  6856.13  19640862720  6.460417e+11     3883632 83.54
"NLD" 2005 0 0  6856.13  2.82337e+10   6.72374e+11    76870172 87.16
"NLD" 2006 0 0  6856.13  41789493248  7.194129e+11    61030974 80.37
"NLD" 2007 0 0  6856.13  60448886784  8.331906e+11   754858701 76.71
"NLD" 2008 0 0  6856.13  84178083840  9.312934e+11  1857436139 75.03
"NLD" 2009 0 0  6856.13  75492417536  8.580856e+11   649134968 79.33
"NLD" 2010 0 0  6856.13  8.24709e+10  8.364397e+11   621769714 91.91
"NLD" 2011 0 0  6856.13 104115871744  8.937017e+11   931428516 93.93
"NLD" 2012 0 0  6856.13 115341615104  8.231392e+11   737828734 95.47
"NLD" 2013 0 0  6856.13 124163178496  8.535394e+11  1417872056 96.52
"NOR" 2002 0 0  7655.05  12497345536  195418341376       61872 43.53
"NOR" 2003 0 0  7655.05  14188949504  228752441344      198444 74.61
"NOR" 2004 0 0  7655.05  19640862720  2.643575e+11      456499 83.54
"NOR" 2005 0 0  7655.05  2.82337e+10  308722073600     4563344 87.16
"NOR" 2006 0 0  7655.05  41789493248  3.454247e+11     6666622 80.37
"NOR" 2007 0 0  7655.05  60448886784  4.008839e+11     2515777 76.71
"NOR" 2008 0 0  7655.05  84178083840  4.619468e+11   163519039 75.03
"NOR" 2009 0 0  7655.05  75492417536  3.863839e+11    65442003 79.33
"NOR" 2010 0 0  7655.05  8.24709e+10  4.285247e+11     2583755 91.91
"NOR" 2011 0 0  7655.05 104115871744  4.981574e+11     3091613 93.93
"NOR" 2012 0 0  7655.05 115341615104  5.097049e+11    11222302 95.47
"NOR" 2013 0 0  7655.05 124163178496  5.223491e+11    13199818 96.52
"PRT" 2002 1 0   5779.5  12497345536  134228680704    65931400 43.53
"PRT" 2003 1 0   5779.5  14188949504  1.649642e+11     2715617 74.61
"PRT" 2004 1 0   5779.5  19640862720  1.891875e+11     2275466 83.54
"PRT" 2005 1 0   5779.5  2.82337e+10  197304565760    31223621 87.16
"PRT" 2006 1 0   5779.5  41789493248  208566927360    66234967 80.37
"PRT" 2007 1 0   5779.5  60448886784  2.401693e+11   507093777 76.71
"PRT" 2008 1 0   5779.5  84178083840  2.620076e+11   601532623 75.03
"PRT" 2009 1 0   5779.5  75492417536  243745767424   211175103 79.33
"PRT" 2010 1 0   5779.5  8.24709e+10  2.383176e+11   746364892 91.91
"PRT" 2011 1 0   5779.5 104115871744  2.448799e+11  1638260298 93.93
"PRT" 2012 1 0   5779.5 115341615104  2.163682e+11  2289940611 95.47
"PRT" 2013 1 0   5779.5 124163178496  224912474112  3494430941 96.52
end

Extract column names from a matrix

$
0
0
Hi,

Is there a command to extract the names of the columns of a matrix? Thanks!

Regards,

Randomly assign year

$
0
0
Hello,
In the following data, I want to randomly assign "foreign" year to "control firm" based on "acquisition percent per year". For instance, I want to assign 1990 to 0.2 percent of control firm, 0.1 percent to 1991 and so on. How can I do this in stata?
Thank you,


foreign acquisition percent per year control firm random sort year
1990 0.2 C15 0.003036765 1990
1991 0.1 C9 0.168831204 1990
1992 0.15 C12 0.179430892 1990
1993 0.35 C10 0.187849179 1990
1994 0.2 C3 0.300511008 1991
C4 0.349749197 1991
C1 0.383394385
C16 0.392541865
C19 0.640032537
C18 0.709030551
C6 0.737769418
C8 0.802163162
C2 0.818150491
C20 0.868747158
C13 0.87968224
C17 0.912942839
C11 0.9380032
C7 0.946397067
C5 0.959596779
C14 0.969432086

memory vs speed tradeoff mata program

$
0
0
Hello everyone,

​I already posted a question pretty close to that one several months ago. I have a mata program that computes basic but heavy linear algebra tasks. It basically checks whether the datatset has more than 10,000 obs and if so, it splits the dataset into subgroups of several thousands to make matrix sizes smaller and limit memory allocation failures. Once the dataset has been split, the program does the required computation. The program is part of a larger ado file. I am programming using Stata MP 13 and my package works perfectly fine even with large datasets (100000 obs) on that version of Stata. However, I tested my program on Stata 12 SE and the external memory allocation failed. I did not use any pointer in the code below. Would it allow me to overcome external memory allocation issues? If so, would it slow down my program significantly or not?

Thanks in advance,

Yannick Guyonvarch

Code:
/*CIC analytic variance*/

version 12

mata:

mata set matastrict on

void intermediary_CIC_variance_step(string scalar one_over_fd, ///
string scalar y, string scalar qd, ///
string scalar isId10, ///
string scalar n, string scalar nd10, ///
string scalar touse, string scalar build3_d, ///
string scalar build4_d, string scalar split_grid) {

real matrix inv_fd,Y,Yd10,Qd,split_matd,split_matd10,res,subsetY,subsetQd,v1,v2,v3,v4,v5,v6,v7,temp_res

real scalar N,Nd10,counterd10,counterd,floord10,floord, ///
i,j,split_gr

real scalar coucou
coucou=1
inv_fd=Y=Yd10=Qd=split_matd=split_matd10=res=temp_res=.

st_view(inv_fd,.,one_over_fd,isId10)
st_view(Y,.,y,touse)
st_view(Yd10,.,y,isId10)
st_view(Qd,.,qd,touse)
st_view(res,.,st_addvar(("double","double"),(build3_d,build4_d)),touse)
Nd10=st_numscalar(nd10)
N=st_numscalar(n)
split_gr=st_numscalar(split_grid)
res[.,.]=J(N,2,0)

    if(Nd10>=10000 & N>=10000) {
        
        floord10=floor(Nd10/split_gr)
        
        if(floord10*split_gr>Nd10) {
        
            counterd10=floord10
        }
        else if(floord10*split_gr==Nd10) {
        
            counterd10=floord10
        }
        else {
        
            counterd10=floord10+1
        }
        
        split_matd10=J(1,counterd10,0)
        
        floord=floor(N/split_gr)

        if(floord*split_gr>N) {
        
            counterd=floord
        }
        else if(floord*split_gr==N) {
        
            counterd=floord
        }
        else {
        
            counterd=floord+1
        }
        
        split_matd=J(1,counterd,0)
        
        for(i=1;i<=counterd10;i++) {
    
            if(i!=counterd10){
            
                split_matd10[1,i]=split_gr*i
            }
            
            else {
            
                split_matd10[1,i]=Nd10
            }
        }
        
        for(i=1;i<=counterd;i++) {
    
            if(i!=counterd){
            
                split_matd[1,i]=split_gr*i
            }
            
            else {
            
                split_matd[1,i]=N
            }
        }
        
    }

    else if (Nd10<10000 & N>=10000) {
            
        floord=floor(N/split_gr)

        if(floord*split_gr>N) {
        
            counterd=floord
        }
        else if(floord*split_gr==N) {
        
            counterd=floord
        }
        else {
        
            counterd=floord+1
        }
        
        split_matd=J(1,counterd,0)
        
        counterd10=1
        split_matd10=J(1,1,Nd10)
        
        for(i=1;i<=counterd;i++) {
    
            if(i!=counterd){
            
                split_matd[1,i]=split_gr*i
            }
            
            else {
            
                split_matd[1,i]=N
            }
        }
    }
            
    else {
        
        counterd=1
        counterd10=1
        split_matd10=J(1,1,Nd10)
        split_matd=J(1,1,N)
    }
    
    for(i=1;i<=counterd;i++) {
        
        subsetY=subsetQd=v1=.
                
        if(i==1) {
        
            subsetY=Y[(1::split_matd[1,i]),1]
            subsetQd=Qd[(1::split_matd[1,i]),1]
            v1=J(split_matd[1,i],1,1)
        }
        else {
        
            subsetY=Y[(split_matd[1,i-1]+1::split_matd[1,i]),1]
            subsetQd=Qd[(split_matd[1,i-1]+1::split_matd[1,i]),1]
            v1=J(split_matd[1,i]-split_matd[1,i-1],1,1)
        }
        
        
        for(j=1;j<=counterd10;j++) {
        
            v2=v3=v4=v5=v6=v7=.
        
            if(j==1) {
            
                v2=subsetY#J(1,split_matd10[1,j],1)
                v3=v1#Yd10[(1::split_matd10[1,j]),1]'
                v4=v1#inv_fd[(1::split_matd10[1,j]),1]'
                v5=subsetQd#J(1,split_matd10[1,j],1)
            }
                    
            else {

                v2=subsetY#J(1,split_matd10[1,j]-split_matd10[1,j-1],1)
                v3=v1#Yd10[(split_matd10[1,j-1]+1::split_matd10[1,j]),1]'
                v4=v1#inv_fd[(split_matd10[1,j-1]+1::split_matd10[1,j]),1]'
                v5=subsetQd#J(1,split_matd10[1,j]-split_matd10[1,j-1],1)
            }
            
            v6=((v3-v2):>=0)
            v7=((v3-v5):>=0)

            if(i==1) {

                res[(1::split_matd[1,i]),1]=res[(1::split_matd[1,i]),1]+rowsum(v7:*v4)
                res[(1::split_matd[1,i]),2]=res[(1::split_matd[1,i]),2]+rowsum(v6:*v4)                
            }
            
            else {
            
                res[(split_matd[1,i-1]+1::split_matd[1,i]),1]=res[(split_matd[1,i-1]+1::split_matd[1,i]),1]+rowsum(v7:*v4)
                res[(split_matd[1,i-1]+1::split_matd[1,i]),2]=res[(split_matd[1,i-1]+1::split_matd[1,i]),2]+rowsum(v6:*v4)
            }
        }                
    }
    res[.,.]=res:/Nd10
    mean(res)
    
}

end

Merging matrices

$
0
0
Dear Forum,
I have a matrix with Leontief Coefficients with a size of 47x47. My aim is to merge the entries into a matrix with a size of 6x6.
I would love to know if a command exists that allows me to specify groups of entries and adding up the coefficients.
The code below shows how I started with the first two entries of the new matrix. A more elegant way would be to know commands that help me to add up all intersections of defined rows and columns. Any help would be highly appreciated.

Kind Regards
Stefan

Code:
import excel using "iotest.xlsx", firstrow;
mkmat crop-other, matrix(A)  rownames(Sectors) ;
   matrix B=J(6,6,0) ;
   matrix rownames B= food textile energy house transp misc ;
   matrix colnames B= food textile energy house transp misc ;
   matrix B[1,1]=A[1,1]+A[1,2]+A[1,7]+A[1,8]+A[2,1]+A[2,2]+A[2,7]+A[2,8]+A[7,1]+A[7,2]+A[7,7]+A[7,8]+A[8,1]+A[8,2]+A[8,7]+A[8,8]+A[9,9] ;
   matrix B[2,2]=A[10,10]+A[10,11]+A[10,12]+A[11,10]+A[11,11]+A[11,12]+A[12,10]+A[12,11]+A[12,12] ;

STATA update issues

$
0
0
Dear all,

May I ask a question on the STATA-update issue? I updated my STATA on Nov. 12 from STATA 13.0 to 13.1. It seems to be an incomplete update because I have problems with "merge" now (error message: pathsplit() in lmatabase, compiled by Stata 13.1, is too new to be run by this version of Stata and so was ignored). Thus I update again using "update all". But I could never connect with www.stata.com. I have already "set timeout1 32000" "set timeout2 32000" and tried many times on different days. I don't think it is an internet problem as I could open the website (www.stata.com) or the gmail website (I am located in China).

Could you please give me any clue? Should I uninstall my STATA 13.0? My version of STATA is Windows 32 bit, SE. Thank you very much for your help!

Best,
April

Simulation exercise in difference-in-difference set up

$
0
0
Hi everybody,

I am currently trying to set up a simulation exercise in Stata SE 14.0 and could use some input. In particular, I have a panel data set with firms and years and would like to solidify my findings from a difference-in-difference estimation by running a simulation, which randomly assigns firm-years to the "treated" (1) or "untreated" (0) groups.

The basic equation to be estimated is yit = aj + ab + ay + b treat * inti,t-1 + eit. I want to replace the real data for "treat" (1/0) with simulated values and re-run the original estimation 1000 times.

I am using the user-written command reghdfe (available from SSC, highly recommended) to deal with a faster estimation of regressions with multiple fixed effects. (Note that this is largely irrelevant for my question.)

The code I am running looks like this:

Code:
set seed 12345
postfile simul beta using simulation, replace

forvalues i = 1/1000 {
  gen order=runiform()
  sort order
  gen plac=0 if treat!=.
  replace plac=1 if _n<=3590 & treat!=.
  drop order
  sort gvkey year
 
  gen ltreat_int=l.treat*int
  reghdfe y ltreat_int, a(year industry bank) cluster(gvkey)
  loc beta=_b[ltreat_int]
  post simul (`beta')
  drop ltreat_int
 
  drop plac
}

postclose simul
use simulation, clear
summarize
I have not worked with simulations before but this estimation will take days even on the fastest PC I have at my disposal. Is there any more efficient way to set this up?

Cheers,
Karsten

Copy/pasted code made Stata think I'm using a Mata programming command!

$
0
0
Halp! I copied and pasted some code from a colleague without realizing it might have embedded programming. I don't use Mata or LaTeX and I'm not even sure how they integrate with Stata. The sad thing is that once I started having this error message, even though I thought I stripped the code by (1) copying and pasting it into Notepad, removing the commands I didn't want (e.g., {tex} commands and pasting it into a clean do-file and then (2) installing and using texdoc to supposedly strip the file and replace it with one that doesn't have tex commands, I'm still getting the following error:

unrecognized command: lstrfun
r(199);

Finally I tried installing lstrfun (which was part of the dofile I copied and pasted from), and when I ran the file this time, when it got to the copied and pasted part it started trying to encode all the string variables in the dataset and ended with invalid syntax:

*run LCAs using runmplus
.
. foreach pony in 1 2 3 4 5 6 7 {
runmplus `aicasvars', ///
> variable(categorical=`aicasvars'; classes=q(`pony'); ///
> cluster is class; idvariable=ID
analysis(type=complex mixture; proc=8;starts=100 20 ///
> output(tech10; tech11; svalues; ) ///
> savelogfile(eulcaV6`pony') ///
> saveinputdatafile(eulcaV6`pony') ///
> saveinputfile(eulcaV6`pony')
}
encoding Id
encoding Q21b
encoding Q21c
encoding Q36c
...

I should mention that this is also after a bunch of restarts and making sure I didn't accidentally turn on Mata (had to look up to see what that was).

OK I tried one more thing--deleting all the spaces between lines and characters (aside from the commands themselves) and running and I got a little further, but I still think there's hidden code, because now I got " unrecognized command: strparse"

Unless you all have some good ideas, I think I will just try uninstalling and reinstalling Stata. But it would be good to know what's going on.

And yes, I will try to learn LaTeX; just not to that point yet.

Thanks!

Michelle

Establishing temporal precedence in survival analysis

$
0
0
Hello,

I'm currently working on a project that tries to investigate whether conflict envolvement increases the hazard of regime failure. I would really appreciate any help with solving the problem below:


My data is in regime-month format, with an observation for every month of the regime's existance.

Ihave a categorical variable that measures whether the regime has ever been involved in any form of conflict, DUM_CON (0=never involved in a conflict, 1=involved in conflict at some point).

I also have a time-varying 'CONFLICT' variable that is coded as 1 if the state has been involved in a conflict in this particular month, and 0 if the regimeis not involved in conflict in this particular month.

I am using Cox regression.

In my results, while CONFLICT seems to have no effect on the hazard of failure, being incolved in conflict at some point (CAR_CON) seems to reduce the hazard of failure significantly.
The problem here is that the longer a regime exists, the more opportunities it has to get involved in international disputes, making me question the results. I wonder whether there is any particular method for establishing temporal precedence here?

Is there any way I can test whether the conflict has occured in the initial years of regime's existance (and therefore the state lasted longer) or whether conflicts occur for those states that managed to survive this far to begin with?

Thank you.

Barbara

R2 of xtivreg2, fe and ivreg2 with dummies

$
0
0
I runned several models using xtivreg2, fe. For curiosity, I runned the same models using ivreg2 using dummies to control for the fixed effects. Not surprisingly, the results are the same. The R2 values of the panel estimator are systematically lower. The correlation between these two sets of R2 is almost perfect, however (at least for my problem). Is there any theoretical relation between the two? In other words: is it possible to calculate one using the value of the other?

Which one would you recommend to report? Both? None?

Assign Year Randomly

$
0
0
Hello,
In the following data, I want to randomly assign "foreign" year to "control firm" based on "acquisition percent per year". For instance, I want to assign 1990 to 0.2 percent of control firm, 0.1 percent to 1991 and so on. How can I do this in stata?
Thank you,

foreign acquisation percent per year control firm random generate year
1990 0.2 C15 0.003036765 1990
1991 0.1 C9 0.168831204 1990
1992 0.15 C12 0.179430892 1990
1993 0.35 C10 0.187849179 1990
1994 0.2 C3 0.300511008 1991
C4 0.349749197 1991
C1 0.383394385
C16 0.392541865
C19 0.640032537
C18 0.709030551
C6 0.737769418
C8 0.802163162
C2 0.818150491
C20 0.868747158
C13 0.87968224
C17 0.912942839
C11 0.9380032
C7 0.946397067
C5 0.959596779
C14 0.969432086

how can identify two group of variable form some separate variables?

$
0
0
Hello every one.
I have five category of dairy products like milk, cheese,,, from one brand. The level of purchasing is define as a ordered value (very low, low,...,very high). It seems some categories have a same purchasing pattern. In fact I want to separate these 5 product into two or three groups. But I don't know the method.
Sorry for my poor knowledge!
Any help will be appreciated.

irf command

$
0
0
I am trying to use Stata's irf command to create impulse response functions

my command goes as follows:

irf create arima12, set(IRFS, replace) step(4)

but i keep getting an error msg saying "cannot compute IRFs after arima"
it did work on some other versions, but mine is Stata 13.0 and it is not working

help please?

Collapse with condition

$
0
0
Dear Stata Users,

My dataset is in panel form. There are 6 variables: IssueCode, IssueName, InvestorCode (defines type of investor), BuyTradingValue, SellTradingValue, date.

I need to calculate sum of BuyTradingValue and SellTradingValue within IssueName and by a certain InvestorCode (I need to sum Buy/Sell of the following investors: (1000+2000+3000+4000+5000+6000+7000) and leave BuyTradingValue/SellTradingValue of the following investors as it is: 8000,9000.

I just have learnt collapse syntax and know that it can create summary statistics but struggling to implement it with a condition.

Here is my dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str12(IssueCode IssueName) int InvestoreCode double BuyTradingValue long SellTradingValue float date
"HK0000050325" "CHINA OCEAN"  1000         0         0 19549
"HK0000050325" "CHINA OCEAN"  2000         0         0 19549
"HK0000050325" "CHINA OCEAN"  3000         0         0 19549
"HK0000050325" "CHINA OCEAN"  3100         0         0 19549
"HK0000050325" "CHINA OCEAN"  4000         0         0 19549
"HK0000050325" "CHINA OCEAN"  5000         0         0 19549
"HK0000050325" "CHINA OCEAN"  6000         0         0 19549
"HK0000050325" "CHINA OCEAN"  7000         0         0 19549
"HK0000050325" "CHINA OCEAN"  8000 431337690 366904090 19549
"HK0000050325" "CHINA OCEAN"  9000  55648150 128496750 19549
"HK0000050325" "CHINA OCEAN"  9001   8415000         0 19549
"KR7000020008" "DongwhaPharm" 1000         0         0 19549
"KR7000020008" "DongwhaPharm" 2000         0         0 19549
"KR7000020008" "DongwhaPharm" 3000         0  19445000 19549
"KR7000020008" "DongwhaPharm" 3100         0         0 19549
"KR7000020008" "DongwhaPharm" 4000         0         0 19549
"KR7000020008" "DongwhaPharm" 5000         0         0 19549
"KR7000020008" "DongwhaPharm" 6000         0         0 19549
"KR7000020008" "DongwhaPharm" 7000         0         0 19549
"KR7000020008" "DongwhaPharm" 8000 128101760 122247860 19549
"KR7000020008" "DongwhaPharm" 9000  31676400  18085300 19549
"KR7000020008" "DongwhaPharm" 9001         0         0 19549
"KR7000040006" "S&TMOTORS"    1000         0         0 19549
"KR7000040006" "S&TMOTORS"    2000         0         0 19549
"KR7000040006" "S&TMOTORS"    3000         0         0 19549
"KR7000040006" "S&TMOTORS"    3100         0         0 19549
"KR7000040006" "S&TMOTORS"    4000         0         0 19549
"KR7000040006" "S&TMOTORS"    5000         0         0 19549
"KR7000040006" "S&TMOTORS"    6000         0         0 19549
"KR7000040006" "S&TMOTORS"    7000         0         0 19549
"KR7000040006" "S&TMOTORS"    8000  22773105  18520385 19549
"KR7000040006" "S&TMOTORS"    9000         0   4252720 19549
"KR7000040006" "S&TMOTORS"    9001         0         0 19549
"HK0000050325" "CHINA OCEAN"  1000     17490         0 19550
"HK0000050325" "CHINA OCEAN"  2000         0         0 19550
"HK0000050325" "CHINA OCEAN"  3000  14650000         0 19550
"HK0000050325" "CHINA OCEAN"  3100         0         0 19550
"HK0000050325" "CHINA OCEAN"  4000         0         0 19550
"HK0000050325" "CHINA OCEAN"  5000         0         0 19550
"HK0000050325" "CHINA OCEAN"  6000         0         0 19550
"HK0000050325" "CHINA OCEAN"  7000         0         0 19550
"HK0000050325" "CHINA OCEAN"  8000 708832685 732554225 19550
"HK0000050325" "CHINA OCEAN"  9000  92420450  93745100 19550
"HK0000050325" "CHINA OCEAN"  9001  10378700         0 19550
"KR7000020008" "DongwhaPharm" 1000         0         0 19550
"KR7000020008" "DongwhaPharm" 2000         0         0 19550
"KR7000020008" "DongwhaPharm" 3000         0  19436000 19550
"KR7000020008" "DongwhaPharm" 3100         0         0 19550
"KR7000020008" "DongwhaPharm" 4000         0         0 19550
"KR7000020008" "DongwhaPharm" 5000         0         0 19550
"KR7000020008" "DongwhaPharm" 6000         0         0 19550
"KR7000020008" "DongwhaPharm" 7000         0         0 19550
"KR7000020008" "DongwhaPharm" 8000 157136730 159998530 19550
"KR7000020008" "DongwhaPharm" 9000  47412800  25115000 19550
"KR7000020008" "DongwhaPharm" 9001         0         0 19550
"KR7000040006" "S&TMOTORS"    1000         0         0 19550
"KR7000040006" "S&TMOTORS"    2000         0         0 19550
"KR7000040006" "S&TMOTORS"    3000         0         0 19550
"KR7000040006" "S&TMOTORS"    3100         0         0 19550
"KR7000040006" "S&TMOTORS"    4000         0         0 19550
"KR7000040006" "S&TMOTORS"    5000         0         0 19550
"KR7000040006" "S&TMOTORS"    6000         0         0 19550
"KR7000040006" "S&TMOTORS"    7000         0         0 19550
"KR7000040006" "S&TMOTORS"    8000  53985034  54552494 19550
"KR7000040006" "S&TMOTORS"    9000    952530    385070 19550
"KR7000040006" "S&TMOTORS"    9001         0         0 19550
end
format %tdNN/DD/CCYY date

May you please help me out with this task?

Thanks a lot in advance.

Medeff command

$
0
0
Dear all,

I would like to use Stata to do a mediation and moderated mediation analysis for my masters dissertation. For the simple mediation analysis I would like to use the 'medeff' command. However when using the command in stata 12 (small stata for students), the command is not recognized. I would kindly like to ask why the medeff command is not recognized?

Moreover, I assume I can also use the 'sem' command for this. Fortunately, this command is recognized. However, when I am implementing the following syntax:

sem (csrrep<- csp)(roa<- csrrep csp)

the following message is received: The following observed variable names will be treated as latent variables: Label, Date, CSRRep, CSP, ROA, ROE, RDexpenses, Y2012, Y2013, Y2014. If this is not your intention use the nocapslatent option, or identify the latent variable names in the latent() option. The latent () option is also not recognized,

Since I am new to Stata I have no idea what I am doing wrong and therefore I would highly appreciate your help!!

Kind regards,

Quint

Mimicking the import excel firstrow option

$
0
0
I have some excel data which is transposed (i.e. the variable names are observations and the time range are the variables). The goal is to clean and format it entirely in Stata. It looks something like this, when imported:
A B C D
Year Ranges 2001-2002 2002-2003 2003-2004
Australia Exp 31 4 14
US Exp 14 14 35
Brazil Exp 436 24 46
My general method (where A,B,C,D are varnames) is

Manually change A's observations to better names (Year Ranges to year, Australia Exp to AUS, etc)
Manually change the years to single years (i.e. 2001-2002 to 2001)
rename A _varname
xpose, varname clear


In the end, my data looks like this:
AUS US BRAZ
2001 31 14 436
2002 4 14 24
2003 14 35 46
However, renaming Australia Exp to AUS just so I can use xpose is rather tedious. I think the general process is good, but manually changing the variable names is a week point. Please note that my actual data is different and has no pattern like "*country name* Exp"

Anyhow, short version is that the import excel firstrow option seems to do a very good job cleaning up strings so they can be used as variable names. I've looked around and tried shortening, removing spaces, etc but it never seems to quite work and sometimes leaves some of the variable names unreadable. With this, I am hoping to do something like

shorten A strings
rename A _varname
xpose, varname clear
split year, parse(-) generate(years)
drop year years1
rename years2 year
order year, first


Is there any way to mimic this option (import excel firstrow) to clean strings quite similarly? If you have any critiques on my overall method, that would be kindly accepted too. Thanks!

propensity scores as weights to create the control groups and combining it with a difference-in-differences approach

$
0
0
Hello,
I want to create comparison group of nonacquired firms involves a two-step matching process.
The first step, a probit regression, estimates the probability of foreign acquisition based on past values of various measures of firm performance. I do the first step as:

xi: probit treat $x2 i.naics2 i.TargetRegion i.year if t==0
predict pscore
generate w=pscore/(1-pscore)
replace w=1 if treat==1

The second step involves using the propensity scores as weights to create the control groups and combining it with a difference-in-differences approach. This second step involves running a weighted difference-in-differences regression, using the propensity score as weights.
How can I do the second step in Stat?
Thank you,
Yilmaz

Heckprob

$
0
0

Hello, I have a question related to " Heckprobit " command. This command uses the process suggested by Van de Ven and Van Praag of (1981) ? Or estimates the parameters jointly by maximum likelihood ? Regards, DR.

How can I copy values from a variable to a different observation?

$
0
0
Hi guys,

I'd appreciate someone's help.
I'd like to know how can I copy a value from one observation to another. I've got married people and the place where they were born. There's an identifier to know who is the husband or wife of who and what I want is to generate a variable that show where your husband or wife was born. Something like this:
conglome vivienda hogar p203
place_born
wh_born
0994 095 11 1 Ayacucho
0994 095 11 2 Lima
Conglome, vivienda and hogar define the home where people belong. p203 determines if it's about a husband or wife (1=husband, 2=wife), place_born is where the person was born and wh_born shows the date of birth of the husband o wife's person.
First observation is a husband and the correspondent wh_born should be Lima (where his wife was born). The same with the second observation (but in this case for the wife).

I've tried with

by conglome vivienda hogar, sort: g wh_born=place_born[p203+1] if p203==1

for husbands, but the problem is that [p203+1] points allways at the second position and sometimes (in the data) husband is in the second position, so wh_born reports the place of birth of the same person. Also, there are more people in the family as son or daughter (which means that p203 has got more categories) and plenty of homes in database. If anyone can help me, I'd really appreciate it.

Thank you so much.

Marissa

Displaying specific output in a loop

$
0
0
Dear all,

I'n using Stata 13.1. I have a balanced panel data with 106 countries.
For each country I want to test if it demonstrates an inverted U shape over time in some variable. For this end I ran a loop which applies -Utest- command.
Yet, as an output I just want to see the P>|t| value of the U shape test for each country.
I tried the following code:
Code:
gen long obs = _n
forval i = 1/106 {      
     su obs if country_code == `i', meanonly      
     di country[r(min)]      
    qui regress ir time time2 if country_code==`i'  
    qui utest time time2        
    local P>|t = e(P>|t)
    di "     P>|t|   = "  
        
}
But it returns:
Albania
P>|t| =
Algeria
P>|t| =
Argentina
P>|t| =

and so on..

Any ideas how can I can receive the required output?
Many thanks for your time!
Anat
Viewing all 73191 articles
Browse latest View live