I am trying to generate a variable (CSSD) for dispersion which is equal to the sum of the squared deviations from the market of each of the following cryptocurrencies. However, not all of the currencies have data that goes back to the start of the period I am analysing. When there is missing values I want Stata to ignore that currency and calculate the statistic based on those with data. I am not sure if I have explained this very clearly but have tried my best. Does anyone have any ideas regarding a solution?
The code I am currently using:
gen SSD = 0
foreach var in Bitcoin Ethereum Cardano Binancecoin XRP Litecoin Chainlink Bitoincash Stellar Nem Dogecoin Theta Monero TRON EOS {
replace SSD = SSD + (`var'DayRtn - MarketDayRtn)^2
}
gen CSSD = 0
replace CSSD = sqrt((SSD/15-1))

Best,

Ted