Convert odd Stata string variable to date -


i have economic data in format yyyy.qx q indicates "quarter" followed x, in [1,4]. interpreted string.

i've tried use date(series, "ymd") , formatting command, encode function.

ideally, i'd end numerical variable indicating like:

  • yyyy.x
  • yyyy.m, "m" first month of quarter
  • yyyymm01, "mm" first month of quarter.

it's best show code tried , stata did or said in response.

such dates quarterly dates treating them else @ best indirect , @ worst quite wrong.

. set obs 1 obs 0, 1  . gen example = "2013.q4"  . gen qdate = yq(real(substr(example, 1,4)),real(substr(example, -1,1)))  . list      +-----------------+     | example   qdate |     |-----------------|  1. | 2013.q4     215 |     +-----------------+  . format qdate %tq   . list      +------------------+     | example    qdate |     |------------------|  1. | 2013.q4   2013q4 |     +------------------+ 

note code indicating date daily date can wrong. encode (incidentally not function, command) cannot here unless specify every string date explicitly value label.

update note function date() not all-purpose function creating kind of date: daily dates. there in fact synonym daily().

this example shows using quarterly() possibility.

. di quarterly(substr("2013.q4", 1,4) + " " + substr("2013.q4", -1,1), "yq") 215 

for variable series containing such string dates, go

. gen qdate = quarterly(substr(series, 1, 4)) + " " + substr(series, -1, 1), "yq")  . format qdate %tq  

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -