Announcement

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

  • Create a variable including the frequency of another variable

    Good morning all,

    Several days that I am stuck on my research paper. I carry out a model on grant loans, the explained variable being the probability of being in default.

    In particular, I have data on the allocation of loan officers in the different districts: ASSIGNMENT: DS01, DS02, ... DS32.

    I would like to show that depending on where the loan officer is assigned, it has an impact on the probability of customer default.
    For example that the agents in the DS23 register many more defaults than the others.

    First, I created this variable:
    gen default_assign = 0
    replace default_assign = 1 if ASSIGNMENT = "DS23"
    replace ...

    However, I found that when I relaunched the model the districts with the most defaulting customers changed. So I wanted to create an assign_default variable depending on the default frequency in each district like:
    default_assign = 0
    replace default_assign = 1 if frequency ("DS23")> 3

    But I don't know how I can do this on STATA.

    Pleaaaase HELP!

  • #2
    Is it possible to share some sample data? From your question it's not clear how the data were structure and how that ">3" can be computed. Please read the FAQ (http://www.statalist.org/forums/help) on how to use -dataex-.

    This should be easily done with -bysort:- and the right kind of -egen- function, it's just that the question is so bare I have no idea how to even make a suggestion.

    Comment

    Working...
    X