There is no direct command for generating the ISOweek (ISO8601) from a date in Stata.
The following single-line formula derives the ISOweek from any date post 1 Jan 1900.
Should you require ISOweeks from _before_ that date, substitute mdy(1,1,1753) for mdy(1,1,1900), and that will get you back to before the Industrial Revolution!
** derived from the EXCELLENT description of
** how to derive an ISOweek from a date
** described here: https://www.sqlservercentral.com/art...so-week-number
** based on a post here: http://stackoverflow.com/questions/7...ql-server-2005
** from "t-clausen.dk"
gen ISOweek =int((doy(7*int((datevariable-mdy(1,1,1900))/7)+ mdy(1,1,1900) + 3)+6)/7)
Related Posts with ISOweek from dates in Stata: Code below
Duplicate cases –assign single random id to all duplicate casesI have a question about how to assign a random id to duplicate cases. I am cleaning survey data and …
rolling regression (from the very beginning) with predicted y and residuals?Dear All, I have this data set, Code: clear input int year double(inf gdp) float(inf1 gdp1) 1990 5…
Seemingly Unrelated Regression (SUR) for ordered logit and random effectsDear All, I am using STATA 16. I am trying to estimate a SUR model. Brief Data: My four dependent…
String and dummy variableI am trying to create a dummy variable that indicates whether each discharge involves readmission. I…
Stepped wedge cluster randomised trial analysisI was wondering if anyone could help and/or direct on how to approach the data from a stepped-wedge …
Subscribe to:
Post Comments (Atom)
0 Response to ISOweek from dates in Stata: Code below
Post a Comment