Hello!
I am exploring new visualizations with Stata, such as a line graph with arrows following an example presented by @Asjad Naqvi on Medium. Say, my data looks like this:
I then attempt to run the following:
But for some reason, The loop makes no changes in the cases_pop_smooth variable. What am I doing wrong?
I am exploring new visualizations with Stata, such as a line graph with arrows following an example presented by @Asjad Naqvi on Medium. Say, my data looks like this:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float date int country2 float(count_total_week cases_pop pos_test cumulative_test) str13 country 3206 0 155 2 .012903226 .012903226 "Voluntary" 3207 0 2432 16 .006578947 .019482173 "Voluntary" 3208 0 6039 12 .001987084 .02146926 "Voluntary" 3209 0 7789 28 .003594813 .02506407 "Voluntary" 3210 0 17312 58 .003350277 .02841435 "Voluntary" 3211 0 18119 47 .002593962 .03100831 "Voluntary" 3212 0 23537 81 .00344139 .0344497 "Voluntary" 3213 0 27981 112 .004002716 .03845242 "Voluntary" 3214 0 31134 98 .003147684 .0416001 "Voluntary" 3215 0 29917 110 .003676839 .04527694 "Voluntary" 3216 0 31244 159 .005088977 .05036592 "Voluntary" 3217 0 31942 174 .005447373 .05581329 "Voluntary" 3206 1 404 2 .004950495 .004950495 "Unvax all" 3207 1 721 12 .01664355 .021594046 "Unvax all" 3208 1 3129 15 .004793864 .02638791 "Unvax all" 3209 1 4510 28 .006208426 .032596335 "Unvax all" 3210 1 5723 25 .0043683383 .036964674 "Unvax all" 3211 1 6604 24 .003634161 .04059884 "Unvax all" 3212 1 11085 35 .00315742 .04375625 "Unvax all" 3213 1 12930 40 .003093581 .04684984 "Unvax all" 3214 1 13876 37 .0026664746 .04951631 "Unvax all" 3215 1 15762 78 .00494861 .05446492 "Unvax all" 3216 1 17063 91 .005333177 .0597981 "Unvax all" 3217 1 16185 111 .006858202 .0666563 "Unvax all" 3206 2 391 7 .017902814 .017902814 "Unvax stu/fac" 3207 2 360 4 .01111111 .029013924 "Unvax stu/fac" 3208 2 854 4 .00468384 .033697765 "Unvax stu/fac" 3209 2 1954 3 .001535312 .035233077 "Unvax stu/fac" 3210 2 3426 13 .0037945125 .03902759 "Unvax stu/fac" 3211 2 3916 18 .004596527 .04362412 "Unvax stu/fac" 3212 2 3803 11 .002892453 .04651657 "Unvax stu/fac" 3213 2 5925 23 .0038818566 .05039843 "Unvax stu/fac" 3214 2 6328 30 .004740834 .05513926 "Unvax stu/fac" 3215 2 6399 54 .008438818 .06357808 "Unvax stu/fac" 3216 2 8154 127 .015575178 .07915325 "Unvax stu/fac" 3217 2 8049 105 .0130451 .09219836 "Unvax stu/fac" 3206 3 1715 11 .006413994 .006413994 "Everyone" 3207 3 3416 17 .004976581 .011390575 "Everyone" 3208 3 3004 10 .003328895 .01471947 "Everyone" 3209 3 1731 2 .0011554015 .015874872 "Everyone" 3210 3 2115 10 .004728132 .020603003 "Everyone" 3211 3 2394 10 .0041771093 .024780113 "Everyone" 3212 3 3785 7 .0018494056 .02662952 "Everyone" 3213 3 4311 15 .003479471 .03010899 "Everyone" 3214 3 5707 27 .004731032 .03484002 "Everyone" 3215 3 6068 25 .0041199736 .03896 "Everyone" 3216 3 5853 26 .0044421665 .04340216 "Everyone" 3217 3 6243 39 .006246997 .04964916 "Everyone" 3208 4 28 0 0 0 "Selective" 3209 4 496 0 0 0 "Selective" 3210 4 1653 5 .0030248035 .0030248035 "Selective" 3211 4 1367 3 .0021945867 .00521939 "Selective" 3212 4 2816 6 .0021306819 .007350072 "Selective" 3213 4 3731 23 .006164567 .01351464 "Selective" 3214 4 3260 13 .00398773 .01750237 "Selective" 3215 4 3939 15 .003808073 .02131044 "Selective" 3216 4 5221 51 .009768244 .031078685 "Selective" 3217 4 5310 43 .008097928 .03917661 "Selective" 3206 999 30560 161 .005268325 .005268325 "No report" 3207 999 34032 212 .006229431 .011497756 "No report" 3208 999 56555 289 .00511007 .016607825 "No report" 3209 999 51274 231 .0045052073 .02111303 "No report" 3210 999 54119 236 .0043607606 .02547379 "No report" 3211 999 51783 179 .003456733 .028930526 "No report" 3212 999 64097 178 .002777041 .031707566 "No report" 3213 999 82817 301 .0036345194 .035342086 "No report" 3214 999 81826 344 .0042040427 .03954613 "No report" 3215 999 84020 470 .005593906 .04514004 "No report" 3216 999 80720 511 .006330526 .05147056 "No report" 3217 999 85794 629 .007331515 .05880208 "No report" end
Code:
sort country date gen cases_pop_smooth =. levelsof country2, local(lvls) foreach x of local lvls { lowess cases_pop date if country2==`x', bwid(0.15) gen(temp`x') nograph replace cases_pop_smooth =temp`x' if country2==`x' drop temp`x' } xtset country2 date xtline cases_pop_smooth, overlay legend(off)
Comment