Announcement

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

  • Generate Variable - StataIC - Panel Data

    Hello,

    I am using StataIC and the panel data file mathpnl. with 2750 oberservations and 57 variables.
    The data file contains panel data for district's expenditures per student from 1992 to 1998.

    In order to run an IV regression, where I want to control for initial spending in 1992, I need to generate a new variable.

    I have tried the code:

    // gen exp1992= rexpp if year == 1992 //

    and this gives me a new variable with the value for expenditures (only) in the year 1992.
    But actually I want my dataset to look like the example in the table below (with the thick letter), where it gives me the value of expenditures in 1992 for every observation.
    rexpp year exp1992
    125.312 1992 125.312
    176.418 1993 125.313
    I have tried several codes but it didn't work out.
    Is there any possibility to adjust my code in order to receive the result?
    Last edited by Lea Birm; 21 Feb 2020, 06:32. Reason: IV

  • #2
    Code:
    bys district: egen wanted= max(rexpp*(year==1992))
    Last edited by Andrew Musau; 21 Feb 2020, 07:35.

    Comment


    • #3
      Dear Andrew,

      thank you very much for your answer but I think I have specified it wrongly.
      Observation Year rexpp exp1992
      1 1992 125.312 125.312
      1 1993 176.418 125.313
      2 1992 144.89 144.89
      (and so on)
      I want it to be determined like this. Can you help me and tell me how I need to change the code ?

      Comment


      • #4
        Take a look at your variable names and replace appropriately. Using the names exactly in #3

        Code:
        bys Observation: egen wanted= max(rexpp*(Year==1992))
        Last edited by Andrew Musau; 21 Feb 2020, 07:46.

        Comment


        • #5
          Finally I got it and it works!! Thank you very much!

          Comment

          Working...
          X