Hello,
I'm trying to learn loops but I have a problem when converting my long list of commands into a loop. I hope someone is willing to help me.
I am using Stata 12.
I used a long list of commands to return any variable between brackets from var A, then the same for B in an attempt to extract these values from var A into a new variable. Now I like to learn how to put this in a loop but its frustrating that I don't know how to do this. Is there anyone willing to show me how I can but the following commands into 1 loop?
What I have is the following:
* egen coreA1 = anyvalue(A), v(29 88 162 192 266 152)
* egen coreB1 = anyvalue(B), v(29 88 162 192 266 152)
* gen cpA=B if .>coreA1>0
* gen cpB=A if .>coreB1>0
* gen coreA=max( coreA, cpB)
* gen coreB=max( coreB, cpA)
* drop coreA1 coreB1 cpA cpB
------------------------------------
A B coreA1 cpA
75 162
152 145 152 145
152 226 152 226
220 192
243 33
-------------------------------------
Any help is much appreciated, thanks!
I'm trying to learn loops but I have a problem when converting my long list of commands into a loop. I hope someone is willing to help me.
I am using Stata 12.
I used a long list of commands to return any variable between brackets from var A, then the same for B in an attempt to extract these values from var A into a new variable. Now I like to learn how to put this in a loop but its frustrating that I don't know how to do this. Is there anyone willing to show me how I can but the following commands into 1 loop?
What I have is the following:
* egen coreA1 = anyvalue(A), v(29 88 162 192 266 152)
* egen coreB1 = anyvalue(B), v(29 88 162 192 266 152)
* gen cpA=B if .>coreA1>0
* gen cpB=A if .>coreB1>0
* gen coreA=max( coreA, cpB)
* gen coreB=max( coreB, cpA)
* drop coreA1 coreB1 cpA cpB
------------------------------------
A B coreA1 cpA
75 162
152 145 152 145
152 226 152 226
220 192
243 33
-------------------------------------
Any help is much appreciated, thanks!
Comment