+ Reply to Thread
Results 1 to 2 of 2

Thread: Stata Help: Indicator Variable Problem

  1. #1
    Points: 1,868, Level: 25
    Level completed: 68%, Points required for next Level: 32

    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stata Help: Indicator Variable Problem



    Hi guys, my problem is probably simple and just a matter of finding the right command.

    I have hundreds of thousands of observations which all have one of 100 codes associated with them. I've gone through these 100 codes and classified them into just 5 broader categories. So in a separate dataset I have this:

    Code-----Type
    56----------1
    32----------3
    78----------1
    23----------2
    12----------2
    09----------4
    95----------5
    .
    .
    .
    (300 more lines of this)

    Now I want to go back to my original dataset and basically write these commands:

    generate type2 = 0
    replace type2 = 1 if code==56
    replace type2 = 3 if code==32
    replace type2 = 1 if code==78
    replace type2 = 2 if code==23
    .
    .
    .
    (300 more of these)

    This is not feasible to do by hand, unfortunately.

    The ultimate goal, if you can't tell from the code, is for each of my observations that has a code associated with it, it would also have a 'type'.

    I would greatly appreciate any pointers in the right direction.

    Regards,
    bowser
    Last edited by bowser; 02-14-2010 at 09:33 AM. Reason: Formatting

  2. #2
    Points: 1,868, Level: 25
    Level completed: 68%, Points required for next Level: 32

    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Found the solution by merging the two datasets using the "joinby" command.

    - Bowser

+ Reply to Thread

Similar Threads

  1. How to create an indicator variable?
    By non-sleeper in forum Stata
    Replies: 0
    Last Post: 11-11-2010, 01:13 AM
  2. Need help with a problem with Indicator Random Variable
    By StatStudent3 in forum Probability
    Replies: 3
    Last Post: 10-05-2010, 07:24 PM
  3. log variable on stata
    By momo in forum Stata
    Replies: 1
    Last Post: 10-02-2010, 08:15 AM
  4. [STATA] Lagged variable
    By GuiGui in forum Stata
    Replies: 6
    Last Post: 02-03-2010, 01:43 PM
  5. Indicator Variable
    By JStats in forum R
    Replies: 3
    Last Post: 08-14-2008, 05:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats