Announcement

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

  • Renaming mutiple dummy variables using a loop

    Hello,

    I have a dataset in which I have created 60 dummy variables (named as dummy1, dummy2, dummy3......and dummy64) using the 'tabulate' command. Now, I would like to rename these variables. For example, I want to rename the dummy1 to Agate; dummy2 to iron; dummy3 to Zinc and so on. How can i do this for all my variables in the simplest form?

    Thank you.

  • #2
    Code:
    rename (dummy1-dummy64) (Agate iron Zinc ...)
    (Edit: assuming the dummys are are ordered this way)

    Are you sure you want to do this? For almost any analysis to follow using factor variable notation would probably be the better choice.

    You might be interested in dummieslab (SSC).

    Best
    Daniel

    Comment


    • #3
      I agree with Daniel, but add that tabulate will have automatically produced informative variable labels, so there is scope in principle to loop over the variable labels to pull out new names.

      In fact I have just recalled that this is precisely what dummieslab does! So, thanks for reminding me of that.

      Comment


      • #4
        Thank you very much daniel klein Nick Cox . That works.

        Comment

        Working...
        X