@Peter_C Your code works. Thank you very much. You are a life saver. @mkeintz Thank you. Your code gives me a STD of all firms' COGSQ in a given datadate (quarter). But I need a progressive STD of COGSQ of each firms when time passes. But your code will surely be a useful reference for me in the furture. @All