Dear all,
I was trying to automate the creation of a two-sided bar graph and then realized that there is something wrong with my code when I try to refer to the value of the variable 'infection' for other regions than the first one (i.e., region == 1).
In the code, I try to create a variable called 'temp', that is by design meant to be equal to the variable 'infection', but Stata confirms that it is not the case (with the command 'assert').
I noted the following: the value of infection for the first region is correctly displayed but the ones for the second region and on, I get just a missing value (shown below):
I am wondering why the commands " di "`=infection[region == 2]'" " and " di "`=infection[region == 3]'" " do not show the right values, i.e, -123457 and -69751.
Can you help me, please, figure out what is going here?
Thank you in advance.
Best,
Otavio
I was trying to automate the creation of a two-sided bar graph and then realized that there is something wrong with my code when I try to refer to the value of the variable 'infection' for other regions than the first one (i.e., region == 1).
In the code, I try to create a variable called 'temp', that is by design meant to be equal to the variable 'infection', but Stata confirms that it is not the case (with the command 'assert').
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(region infection) 1 -259131 2 -123457 3 -69751 4 -65337 5 -33808 6 -33306 7 -30560 8 -25685 9 -11081 10 -5423 end gen temp = . qui glevelsof region, local(test) foreach i of local test { replace temp = infection[region == `i'] if region == `i' } assert temp == infection
Code:
di "`=infection[region == 1]'" -259131 di "`=infection[region == 2]'" . di "`=infection[region == 3]'" .
Can you help me, please, figure out what is going here?
Thank you in advance.
Best,
Otavio
Comment