This is something that I have been Googling but couldn't find an answer to.

I need to generate a new variable by using the command rowmean but with a condition that the respondent should have answered at least 4 questions/variables

my code is egen newvar = rowmean (var1 var2 var3 var4 var5 var6)
This is obviously wrong because I dont have the condition of taking the mean ONLY if the respondent has an answer to at least 4 of these variables

Hope someone can help! Thanks!