Create a Sequential Serial Number for Days, Weeks, Months, Quarters
Create a Sequential Serial Number for Days, Weeks, Months, Quarters
For forvalue loop in Stata, we need a series of values placed with equal gaps. If we need to run a loop on months or weeks, we need to create an indicator variable that tracks months or weeks since a given date. For that we, first need to generate year, month, or week. indicators as follows. Suppose we have date variable that tracks time
To create year indicator;
gen year = year (date)
Similarly, for month and week indicator, the code is;
gen month = month (date)
gen week = week (date)
Now to create month serial number;
gen month_serial = ym(year, month)
qui sum month_serial
replace month_serial = month_serial - r(min) + 1
Similarly, to create week serial number;
gen week_serial = yw(year, week)
qui sum week_serial
replace week_serial = month_serial - r(min) + 1
**********************
Tags:
STATA, Create a Sequential Serial Number for Days, sequential Weeks in Stata, Months, Quarters
serial number of Weeks in Stata, generate a date indicator variable in Stata, generate a month indicator variable, generate a week indicator variable, week tags in stata, month tags in stata,