Announcement

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

  • Removing the '0' from yyyy_mm-variables for months january till september

    I have a list of variables showing the income status of an individual in a given month in a given year. The variable format is 'income_'yyyy'_'mm'' where 'yyyy' refers to the year and 'mm' refers to the month. For example, the income status for october 2021 is shown as 'income_2021_10' and the income status for august 2021 is shown as 'income_2021_08'.

    For purposes to fit my other code, I need the variables to exclude the first zero in the month, for the months january till september. That is, the month should go '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12' insted of going '01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12', so for example income status for august 2021 would be shown as 'income_2021_8'.


    Any suggestions to rename the variables in an efficient manner?

  • #2
    Code:
    rename income_2021_0* income_2021_*

    Comment


    • #3
      Thank you, Øyvind!

      As an addition: I needed to do this for all years 2014-2021. This could be done writing:

      Code:
      forval i = 2014/2021{
      ren income_`i'_0* income_`i'_*
      }
      Last edited by Emil Alnor; 24 Feb 2022, 05:51.

      Comment


      • #4
        no need for looping,
        Code:
        rename income_20*_0* income_20*_*

        Comment

        Working...
        X