Hi, I was converting string date data (variable Fdate and Pdate, they look like "20100201") into numeric data.

Code:
clear
input str6  FirmNo Yr Fdate Pdate 
 002410 2010 20100120 20100221 002410 2011 20110121 20110222 002410 2012 20120124 20120222 002319 2010 20100127 20100219 002319 2011 20110124 20110220 002319 2012 20120119 20120222 002590 2010 20100201 20100209 #this observation is important! end
Since Fdate and Pdate are string data, I used real() to turn them into date data.

Code:
gen PrelimDate = real(Fdate)
And then I turned them into date format with this code, following advice:

Code:
gen GoodFDate = daily(string(PrelimDate, "%8.0f"), "YMD")
But there were some missing observations in GoodFDate compared to PrelimDate.

As I look through the dataset I've found that some Fdate - when they are first or last day of the month - were misconverted as 20100200. (originally it was 20100201.)

That is the reason that the number of observations for GoodFDate was a bit smaller than that of PrelimDate.

My question is,
1. why did this happen?
2. How can I fix it?

Please help!