Wednesday, January 26, 2011

STATA: Mass renaming variables

Have a bunch of variables with the same beginning of their name, but you want them to be named something else? E.g.
pop1961
pop1962
pop1963

You could -reshape long-, then -rename-, then -reshape wide-, but that's ugly, takes forever, will generate missing values if you don't have all the years, doesn't work for things not years, etc. etc.

Instead, try:
-renpfix-

E.g. -renpfix pop mom-

Now you've got:
mom1961
mom1962
mom1963

7 comments:

  1. -renpfix- is now (> v12.0) included in the syntax of -rename group-.

    Most of what is this seems to stem from Nick Cox's -renvars- (still available on SSC).

    ReplyDelete
  2. Hardly ever make comments on blogs but enjoyed spending some time reading yours, Thanks for all your work.
    Buy Pre Written Essays
    Online Writing Services
    Accounts Software For Small Business

    ReplyDelete
  3. THIS IS GENIUS. Thank you for saving me from wasting several hours of life!

    ReplyDelete
  4. You just saved me lots of hours. Thank you!

    ReplyDelete
  5. I really enjoyed reading your blog post! Your insights on the topic were interesting and informative. I especially appreciated your practical tips on how to implement the ideas you discussed. Thanks for sharing your knowledge with us, and I look forward to reading more from you in the future!unstructured data management.

    ReplyDelete