I have string date variables. My attempts below to convert these to numeric variables have failed. Any help much appreciated.
I want to convert these to numeric data for further manipulation. To get rid of the hyphens I typed
I then used the following code:
This produces missing values as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str9 date "01-Apr-12" "01-Apr-12" "01-Apr-12" "02-Apr-12" "02-Apr-12" "03-Apr-12" "04-Apr-12" "04-Apr-12" "05-Apr-12" end
Code:
replace date=subinstr(date,"-","",.)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str9 date "01Apr12" ...output omitted "05Apr12" end
I then used the following code:
Code:
gen numerical_date=date(date,"DMY")
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float numerical_date . . . . . . . . . end
Comment