Dear All, I found this question here (https://bbs.pinggu.org/thread-10256921-1-1.html). The data set is
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long id double(t yq1)
  1 17531 191
  1 17532 192
  1 17713 193
  1 17805 194
  1 17897 195
  1 17898 196
  1 18078 197
  1 18170 198
  1 18262 199
  1 18263 200
  1 18443 201
  1 18535 202
  1 18627 203
  1 18628 204
  1 18808 205
  1 18900 206
  1 18992 207
  1 18993 208
  1 19174 209
  1 19266 210
  1 19358 211
  1 19359 212
  1 19539 213
  1 19631 214
  1 19723 215
  1 19724 216
  1 19904 217
  1 19996 218
  1 20088 219
  1 20089 220
  1 20269 221
  1 20361 222
  1 20453 223
  1 20454 224
  1 20635 225
  1 20727 226
  1 20819 227
  1 20820 228
  1 21000 229
  1 21092 230
  1 21184 231
  1 21185 232
  1 21365 233
  1 21457 234
  1 21549 235
  1 21550 236
  1 21730 237
  1 21822 238
  1 21914 239
  1 22005 240
  1 22096 241
  1 22188 242
563 17531 191
563 17532 192
563 17713 193
563 17805 194
563 17897 195
563 17898 196
563 18078 197
563 18170 198
563 18262 199
563 18263 200
563 18443 201
563 18535 202
563 18627 203
563 18628 204
563 18808 205
563 18900 206
563 18992 207
563 18993 208
563 19174 209
563 19266 210
563 19358 211
563 19359 212
563 19539 213
563 19631 214
563 19723 215
563 19724 216
563 19904 217
563 19996 218
563 20088 219
563 20089 220
563 20269 221
563 20361 222
563 20453 223
563 20454 224
563 20635 225
563 20727 226
563 20819 227
563 20820 228
563 21000 229
563 21092 230
563 21184 231
563 21185 232
563 21365 233
563 21457 234
563 21549 235
563 21550 236
563 21730 237
563 21822 238
end
format %td t
format %tq yq1
For each id, and for each first (not the second, third, and fourth) quarter of each year, I'd like to replace the first date, say "01jan2008", with the last date, say, "31mar2008". My method is
Code:
gen d = dofq(yq1)
*format d %td
gen d1 = d-1
*format d1 %td
bys id: gen w = d1[_n+1]
format w %td
replace w = t if w == .
and wonder if there is better way to do this. Thanks.