Announcement

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

  • Replacing a value in one column with a value in another column if that value equals 15

    Hello,

    I am a beginner in Stata. I am trying to replace (or generate in a new column) a value in column 1 with the value for that same observation in another column.

    I have tried the command replace var1 = var 2 if var 1 ==15 but without success.

    Could someone help me?

    Kind regards,
    Sophie

  • #2
    There is nothing obviously wrong with -replace var1 = var 2 if var 1 ==15- as a Stata command. And it is anybody's guess what you mean by "without success." So please help those who want to help you by providing the crucial information needed: show example data that illustrates your problem (using the -dataex- command to do so), show the exact command you ran (copy/pasted directly from your do file, log file, or Results window--do not edit it in any way) and the exact results that you got from Stata. Then, unless it is blatantly obvious, explain in what way those results differ from what you were looking for.

    If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3

      Thank you very much. In the meantime I was able to identify the problem, but I will keep your input in mind on how to ask a question properly next time.

      Thank you for your time!

      Comment

      Working...
      X