Stata Tip: How to keep variable label after collapse

23Mar10

One of the most annoying defects of Stata 10 is that after collapse, you may lose variables labels. However, it’s not difficult to solve this issue. This StataCorp link will guide you. But I provide the code here too.

  • Copy variable labels before collapse
  • Rename after collapse
  •    foreach v of var * {
     local l`v’ : variable label `v’
            if `”`l`v””‘ == “” {
             local l`v’ “`v'”
          }
      }

     

  • RENAME:
  •   foreach v of var * {
         label var `v’ “`l`v””
      }

Powered by ScribeFire.



One Response to “Stata Tip: How to keep variable label after collapse”

  1. 1 petertrabertgoff

    This is great – so helpful! (too bad collapse doesn’t have “retain var labels” as an option)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: