Announcement

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

  • Renaming groups of variables

    Hello,

    I was wondering if it is possible to rename groups of variables using the foreach command or similar.

    I have been provided questionnaire data where the variable names include the question stem like this:


    A1howoftendoyoufeelsad
    A2howoftendoyoufeelanx
    A3howoftendoyoufeelstres
    .......
    A50howoftendoyoufeelguilt
    I would quite like to rename my variables along the lines of...
    mentalhealth_1
    mentalhealth_2
    mentalhealth_3
    ........
    mentalhealth_50

    Is this possible and how would I go about doing this?

    Many thanks for any advice.




  • #2
    If the original variables are in the order you show in that data set and there are no other variables intervening, you can do it with:

    Code:
    rename (A1howoftendoyoufeelsad-A50howoftendoyoufeelguilt) mentalhealth_#, addnumber
    Another approach which works if all of the variables begin with A, followed by a number, followed by howoftendoyoufeeland then some ending:
    Code:
    rename (A#howoftendoyoufeel*) mentalhealth_#
    Last edited by Clyde Schechter; 22 Jan 2023, 12:06.

    Comment


    • #3
      Thank you, this solved the problem perfectly!

      Comment

      Working...
      X