Announcement

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

  • Appending datasets with different variable names, same variable labels

    Hi,

    I'm a bit of a noobie at this but hope someone can help! I wish to append datasets which have different variable names but the same variable labels. I can't seem to find a way of doing this (although perhaps I'm missing something obvious).

    I can either think to rename all variables in each dataset to the value of the label, or to append it in such a way that it does this automatically.

    The problem is, I don't know how to do either of those things!

    Thanks for help in advance,
    Jake

  • #2
    Welcome to the Stata Forum / Statalist,

    I believe the best approach for you problem is presenting data to work with. It can be a toy example as well.

    Please take a look at the FAQ, particularly the topic about sharing data/command/output. You may use the CODE delimiters or the command - dataex - , directly, in case the Stata version is 15.1, or you may install the SSC dataex for that matter as well.

    Also, this thread may be helpful to you.
    Last edited by Marcos Almeida; 26 Feb 2018, 05:33.
    Best regards,

    Marcos

    Comment


    • #3
      Cross-posted at https://www.reddit.com/r/stata/comme...h_label_value/

      Our policy on cross-posting is explicit in the FAQ Advice, as also referenced by Marcos, whose advice is excellent. You are asked to tell us about it.

      Conversely, people who follow Reddit routinely (I don't) might appreciate a cross-reference to here, but I'll leave that up to you or anyone else who posts there.

      In general, variable labels won't be suitable as variable names, as all kinds of characters are allowed that aren't allowed in variable names, and labels can be longer.

      You could try renaming variables to a version of their labels, using strtoname() but if you are new to Stata then I can't guarantee your not getting problems of that approach that would in turn stretch anyone's Stata skills.

      I would just
      append any way and resign yourself to cleaning up the result. I get this routinely with students and colleagues who operate Excel-like and keep different subsets of their data in different files or worksheets and then realise that (a) they need to combine them (b) they have not been consistent with their metadata.

      Whatever occurs in one dataset under a unique name will just be added to the dataset under that name. You then clean up later.


      lookfor is good for looking at text in variable labels as well as variable names too.

      Comment

      Working...
      X