Announcement

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

  • Weighting variable for aggregate data

    I have an aggregate dataset and would like to create a weight variable using airline 1, n = 553 and airline 2, n = 678, Any assistance will be appreciated.


    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(airline injuries) double gender byte XYZowned
    1 11 0 1
    1  7 0 0
    1  7 1 0
    1 19 0 0
    2  9 0 0
    2  4 1 1
    2  3 1 0
    2  1 1 0
    2  3 0 1
    end
    ------------------ copy up to and including the previous line -------

  • #2
    Well, if all you have are these two airlines, this is very simple:
    Code:
    assert inlist(airline, 1, 2)
    gen wt = cond(airline == 1, 553, 678)
    But if this is just a small example from a substantially larger data set, then a different approach may be in order. If you have a large number of airlines, I suggest you create a new data with just two variables: airline and value of the weight variable. I don't know where your weight variable comes from, but if it is already in an existing data set, then you don't even have to do that. Or it may be something you can download from somewhere on the internet and import into Stata.

    Anyway, once you have that separate dataset of just airlines and corresponding weights:
    Code:
    use general_airline_dataset, clear
    merge m:1 airline using weight_data_set

    Comment

    Working...
    X