split separate snapshot || STATA | Data Management | Econometrics Melody | U/Graduate | Mphil /Phd

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ม.ค. 2025

ความคิดเห็น • 3

  • @danielomondionyango7163
    @danielomondionyango7163 8 หลายเดือนก่อน

    good thanks

  • @peepepepe3616
    @peepepepe3616 4 หลายเดือนก่อน

    Hello I have a question. I have one string variable which have 4 characters the first two are the houres a the two second are the minutes How can I Split that variable into to variable one for the houres and other for the minutes?

    • @EconometricsMelody
      @EconometricsMelody  4 หลายเดือนก่อน

      Thank you for your question. I hope the following example clarifies your query:
      clear
      set obs 100
      gen time = runiformint(1000, 2400)
      tostring time, replace
      gen hour = substr(time, 1, 2) // Extract the first two characters for the hour
      gen min = substr(time, 3, 2) // Extract the third and fourth characters for the minutes
      // Convert hour and min to numeric
      destring hour, replace
      destring min, replace