Announcement

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

  • expand data?

    Dear All, I have this data set.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 P float(t x)
    "A" 0          2
    "B" 1  10.333333
    "C" 0          1
    "C" 1         -5
    end
    There are two observations when P="C" (with t=0 and 1). This is what I need, and don't need to do anything.

    However, when P="A", only one observation is available (t=0), I need another observation to be exactly the same as the (t=0) observation but with t=1, and x=0.

    Similarly, when P="B", only one observation is available (t=1), I need another observation to be exactly the same as the (t=1) observation but with t=0, and x=0.

    The desired result is something like
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 P float(t x z)
    "A" 0          2  1
    "A" 1          0  1
    "B" 0  0  2
    "B" 1  10.333333  2
    "C" 0          1  3
    "C" 1         -5  4
    end
    Any suggestions are highly appreciated.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    Try
    Code:
    fillin P t
    replace x = 0 if _fillin

    Comment


    • #3
      Dear Kelvin, Thanks for this very helpful suggestion.

      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment


      • #4
        Dear Kelvin, Could you have a look at the follow-up question here.
        Ho-Chuan (River) Huang
        Stata 17.0, MP(4)

        Comment

        Working...
        X