I have a multiple cross-sectional dataset, where I am trying to create the following index:

Dit = (Sum all dit until k)/Kt

In other words, sum the values for all d variables and then divide by the number d variables for that year.

In my dataset, i have 4 variables that i need to look at but for some years only three or two are present so to calculate my index I don't want to just include individuals that had all four. I don't want them to be treated as missing. Instead, i want the aggregated variables to be divided by say 3 instead of 4 if only 3 variables are present. How do i go about creating this Kt?

My four variables are: racmar, racpeers, racpres and racseg. They are byte variables (not string) and are non binary.