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
Need help with nested logit marginal effectsDear scholars, I am having problem estimating the marginal effects after the estimation of my nested…
Omitted dummy variables due to collinearity, but missing values should prevent them entering the modelDear Statalisters, I am using Stata SE 17 on Windows 10. I'm conducting a panel data analysis with t…
Change axis label specifications twoway graphHello, I am tyring to group values if the follwing changes of the y-axis label would be possible: -…
Speed comparison: Passing data vector by name vs pointers in Mata | StataI was experimenting with different uses of pointers. Turns out that in a larger dataset, pointer mig…
Why does Stata graph box not ignore missing values _hi Stata Gurus, I am trying to check the outliners in my data. For example, the total asset (ta) of …
Subscribe to:
Post Comments (Atom)
0 Response to ISOweek from dates in Stata: Code below
Post a Comment