Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to convert funky variable into inches

    I am a brand-new STATA user and I apologize if this has been asked already, but I've Googled my question to death without any success and now I'm turning to you all. I have a height variable that I need to convert into inches. The data is in the form of 500, 501, 502, etc., where the first digit is the height in feet and the last two digits are inches. I need to convert this variable into inches(so, for example, 502 needs to be converted to 62). Any ideas? I'm desperate and on a time crunch, and I'm regretting my liberal-arts educational background.

  • #2
    Welcome to Statalist, Shane.

    Here's something that I think does what you want.
    Code:
    . input strange
    
           strange
      1. 501
      2. 506
      3. 600
      4. end
    
    . generate height = floor(strange/100)*12 + mod(strange,100)
    
    . list
    
         +------------------+
         | strange   height |
         |------------------|
      1. |     501       61 |
      2. |     506       66 |
      3. |     600       72 |
         +------------------+

    Comment


    • #3
      Thanks x 106 !!!

      Comment


      • #4
        Note that dates are often presented in this way as integer strings to be parsed, e.g. 200401 or 20041 for 2004q1 and other variants for monthly and daily dates. When bespoke functions fail numeric parsing using floor() and mod() is often the way in. I've never quite seen the case for a generic command, as the concrete solutions once seen are easier than any such command would be.

        Comment

        Working...
        X