Announcement

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

  • Grouping data by two variables and deal with them to generate dummy

    Hello everyone in the community! I'm having some problems with the data, thanks in advance for all your help!

    A project (identified by pid) may submit its business plan to multiple investors (identified by investor_uid) multiple times (each different submission is identified by v1), and in each submission, the investor will give any one of three responses (or none of them).
    I would like to create a variable bp_response56, which divides the submissions with the same pid and same investor_uid into a group, and identifies whether a particular investor gives response_5 or response_6 for a particular project, and if it gives any of them, the variable is 1, otherwise it is 0.
    Since a project may submit its business plan to one investor multiple times, I can't generate the variables directly with expressions like "gen bp_response 56 if bp_response_4_negativecomments=="True" ", so I hope that I could get suggestions and guidance from you.

    Here is my sample data


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(v1 pid investor_uid) str5(bp_response_4_negativecomments bp_response_5_askfordetails bp_response_6_askcontactinfo)
    833542 80259  26582 "False" "False" "False"
    833533 80259 379987 "False" "False" "False"
    833547 80259 609757 "True"  "False" "False"
    833532 80259 552841 "False" "False" "True"
    833531 80259 579251 "True"  "False" "False"
    833545 80259  54304 "False" "False" "False"
    833534 80259 510785 "False" "False" "False"
    833538 80259  45808 "False" "False" "False"
    833546 80259 514253 "False" "False" "False"
    833540 80259 583987 "False" "False" "True"
    833544 80259 542169 "False" "False" "False"
    833535 80259 400511 "False" "False" "False"
    833536 80259  10608 "False" "False" "False"
    831641 80261 142045 "False" "False" "False"
    817318 80261 114743 "False" "False" "False"
    821473 80261 474495 "False" "False" "False"
    817320 80261  41412 "False" "False" "False"
    818798 80261  10946 "False" "False" "False"
    818794 80261 265801 "False" "False" "False"
    817335 80261  36708 "False" "False" "False"
    821470 80261 476455 "False" "False" "False"
    end

    Wish you have a great day!

  • #2
    maybe,
    Code:
    egen wanted = max(bp_response_5=="True" | bp_response_6=="True"), by(pid investor_uid)

    Comment


    • #3
      Originally posted by Øyvind Snilsberg View Post
      maybe,
      Code:
      egen wanted = max(bp_response_5=="True" | bp_response_6=="True"), by(pid investor_uid)
      COOL! It really works for me!
      Thanks a million!

      Comment

      Working...
      X