Announcement

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

  • Replacing values of multiple variables at once

    I have 9 variables (road_access, market_access, storage_access, insurance_access, input_access, output_access, support_access, processing_access, credit_access) with binary responses coded as yes = 1 no =2.

    I wanted to replace all he values of no to 0 for all variables at once.
    I tried:

    local infra_access *_access
    replace infra_access= 0 if infra_access ==2

    or
    recode infra_access (2=0)

    In both cases, it says "you specified too many variables".

    Can anyone help me with the appropriate codes.
    Last edited by Bibek Sapkota; 29 Apr 2019, 23:10.

  • #2
    Code:
    recode *_access (2 = 0)
    is valid Stata syntax and does what you want. If you get an error message from applying this command, then post back showing, a) an example of your data using the -dataex- command, b) the exact code you typed and the exact response you got from Stata (including the error messages) posted between code delimiters. DO NOT EDIT the code and Stata response in any way: there are no unimportant details in code.

    If you are running version 15.1 or a fully updated version 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.

    If you are not familiar with code delimiters, read Forum FAQ #12 for instructions.

    For additional assistance on both -dataex- and code delimiters, if needed, watch David Benson's instructional video at https://youtu.be/bXfaRCAOPbI.

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

    Comment


    • #3
      Hi Schechter,
      Code:
       recode *_access (2=0)
      worked perfectly.
      Many thanks for this. Thanks are more due to code delimiter and dataex.

      Bibek
      Last edited by Bibek Sapkota; 30 Apr 2019, 03:22.

      Comment

      Working...
      X