Hi all,

I'm trying to iteratively build up a local to make ylabel markers for a graphing command i'm working on. The ylabels will be structured normally:
Code:
ylabel(1 "First description of 1" 2 "Second description" etc., suboptions)
But instead of 1, 2, 3, etc. for the ylabel markers, I want the numbers to be spaced out according to upper and lower values of a variable, grouped by another variable.

This data and the following explanation should make what i'm trying to do clearer:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(treat mean) str24 groupvar float(se ci_upper ci_lower seq)
0  49.44049 "Gender"                    1.595464   52.5676  46.31338  1
1  50.91611 "Gender"                   1.5531636   53.9603  47.87191  6
2  52.00411 "Gender"                    1.602462  55.14494  48.86329 11
3  51.34328 "Gender"                   1.5774164  54.43502  48.25155 16
0 13.835197 "Black / African American" 1.1017978  15.99472 11.675673 25
1 14.946963 "Black / African American" 1.1077493  17.11815 12.775774 30
2  13.56629 "Black / African American" 1.0983455 15.719048 11.413532 35
3   16.0199 "Black / African American" 1.1575806  18.28876  13.75104 40
0 20.854527 "Hispanic / not Hispanic"   1.296455  23.39558 18.313475 49
1 21.311476 "Hispanic / not Hispanic"  1.2722796 23.805143 18.817808 54
2  21.47996 "Hispanic / not Hispanic"  1.3172672   24.0618 18.898115 59
3 21.393036 "Hispanic / not Hispanic"  1.2941954  23.92966 18.856413 64
end
In this example the spacing is 5 for each value of seq within a given value of groupvar and then 9 between values of groupvar (i.e. seq runs 1, 6, 11, 16 within gender, and then jumps to 25 before starting with Black/African American). I want the y-axis labels to fall exactly half way between the lowest and highest numbers of seq for each value of groupvar, so for the example data above i'd end up with something like
Code:
ylabel(8.5 "Female" 32.5 "Black/African American" 56.5 "Hispanic")
.

I've attempted to build a local that's abstract enough to do this for any logic of seq, i.e. skipping 2 within a given value of groupvar and 4 between, etc. The logic for finding the numbers is: seq[_N]-((seq[_N]-1)/2), but i'm running into issues trying to combine bysort with the local. This is what I have so far:
Code:
levelsof groupvar
local ylabs
        forval i = 1/`r(r)'{
            bysort groupvar (treat): local ylabs `ylabs' seq[_N]-((seq[_N]-1)/2)
        }
Any pointers would be wonderful. I'm pulling the actual labels from a varlist in another dataset (not shared here) and should be able to figure out how to integrate those no problem. My challenge is figuring out the numbers.