Announcement

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

  • replacing variables in order

    Hello,

    I have a series of variables with phone numbers (in string format) that are as follows:



    I would like to replace the values of the missing phone numbers with available numbers such that all missing numbers are at the trailing end of the series (ex. if there are 2 available numbers, these should be populated in t_phone1 and t_phone2 and the remaining variables should be missing". Is the best way to approach this replacing variables starting from the right most columns until the desired order is achieved?

  • #2
    This is a poorly constructed question and is missing information.

    Are you looking to sort on phone number with missing at the bottom?

    Comment


    • #3
      If your phone number variables are formatted such that there are no spaces, you could use the word function to your advantage:

      Code:
      gen tempvar=""
      foreach var of varlist phone1 phone2 phone3 {
      replace tempvar=tempvar+" "+`var'
      }
      forvalues i = 1/3 {
      gen t_phone`i'=word(tempvar,`i')
      }
      drop tempvar

      Comment

      Working...
      X