Dear
I'm trying to assig one specific data observation to a local macro named 'x' for posterior use in 'forvalue' loop computation, like in the following code.
The data are structured as panel with 150 countries from 1962 to 2015.
For each year in the panel, from 1962 to 2015, I need to get the value of variable GDPp corresponding to country "USA" (my benchmarking country)
After that divide all GDPp of others countries by this 'x' and store the result into the NewVar.
Note that the "replace ..." is a second loop computing NewVar for all countries each year within the first 'forvalues' loop.
Of course, local macro works as a scalar so the line -- local x = GDPp if year==`i' & code=="USA" -- doesn't works because 'if' statement doens't apply.
My problem is that I have stucked in visualize an alternative procedure to assign the GDPp of USA of a specific year to a local macro.
Maybe the solution could be obvious,
Thanks you by answer
I'm trying to assig one specific data observation to a local macro named 'x' for posterior use in 'forvalue' loop computation, like in the following code.
The data are structured as panel with 150 countries from 1962 to 2015.
For each year in the panel, from 1962 to 2015, I need to get the value of variable GDPp corresponding to country "USA" (my benchmarking country)
After that divide all GDPp of others countries by this 'x' and store the result into the NewVar.
Note that the "replace ..." is a second loop computing NewVar for all countries each year within the first 'forvalues' loop.
Of course, local macro works as a scalar so the line -- local x = GDPp if year==`i' & code=="USA" -- doesn't works because 'if' statement doens't apply.
My problem is that I have stucked in visualize an alternative procedure to assign the GDPp of USA of a specific year to a local macro.
Code:
xtset code year sort code year gen NewVar = . forvalues i=1962/2015 { local x = GDPp if year==`i' & code=="USA" replace NewVar = GDPp/`x' if year==`i' }
Thanks you by answer
Comment