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
0 Response to How to refer to specific pairs of observations-variables using locals, ex: "`=price[make == "AMC Concord"]'"
Post a Comment