Hello, I am attempting to create a loop that goes through a sequence of variables. There are three distinct variable sets: the first set has numeric suffices running from 1-2 (containing the acronym PSH), the second 1-4 (ES), and the third 1-2 (TH) once again. I am renaming them all to Address2-9 (it's basically concatenating three address parts into one complete address field). I want to set an alternating number count within the loop that would go only up to 2 for the first and third group of variables and then up to 4 for the second.
I devised the below loop as a general example. although it does not work:
Code:
. loc i=2
. loc k=1
. foreach j in PSH ES TH {
2. g Address`i' = Serv`j'Loc`k'+", "+Serv`j'Loc`k'1+", NJ "+Serv`j'Loc`k'2 if !missing(Serv`j'Loc`k')
3. drop Serv`j'Loc`k' Serv`j'Loc`k'1 Serv`j'Loc`k'2
4. loc ++i
5. loc ++k
6. }
(49 missing values generated)
(51 missing values generated)
ServTHLoc3 not found
r(111);
end of do-file
r(111);
0 Response to Setting an alternating number count within a loop
Post a Comment