Announcement

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

  • Regression using change scores

    Hi all,

    I would like to run a regression using change scores (dependent variable). I have repeated cross section data of two survey rounds (1995-2005). I have two observations for each individual (corresponding to each round). My dependent variable ‘degre’ is a score that was recorded in 1995 and again in 2005. I would like to calculate a change score for this variable such that:

    Change in degre= degre(2005) – degre(1995) for each individual in the data.

    I have tried running the following code:

    Code:
    bysort Findid (round): gen deltascore = degre – degre[1] if (round==2012)
    which returned an error of “invalid ‘-‘”

    Below is an example of my data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int round str11 Findid float degre int age byte region
    1995 "0601004802"   3.2495956 30 4
    2005 "0601004802"    1.688907 37 4
    1995 "0601005902"   .16159777 26 4
    2005 "0601005902"    2.613617 32 4
    1995 "0601025702"   .16159777 29 4
    2005 "0601025702"   .16159777 35 4
    1995 "0601037702"    .4169497 30 4
    2005 "0601037702"    1.869309 36 4
    1995 "0601038302"  -1.4377835 33 4
    2005 "0601038302"     -2.9264 40 4
    1995 "0601054402"     -2.9264 31 4
    2005 "0601054402"  -1.4377835 35 4
    1995 "0601056302"   1.0529283 33 4
    2005 "0601056302"   -.4743808 39 4
    1995 "0601058302"   .16159777 22 4
    2005 "0601058302"   .16159777 29 4
    1995 "0601058602"   .16159777 24 4
    2005 "0601058602"    .4169497 30 4
    1995 "0601059402"   3.2495956 28 4
    2005 "0601059402"    1.161258 34 4
    1995 "0601060202"    1.161258 18 4
    2005 "0601060202"   1.9776386 24 4
    1995 "0601060302"   .16159777 19 4
    2005 "0601060302"   1.9776386 25 4
    1995 "0601061202"   1.0529283 26 4
    2005 "0601061202"   .16159777 33 4
    1995 "0601061302"   .16159777 23 4
    2005 "0601061302"    .9779783 30 4
    1995 "0601061602"   .16159777 21 4
    2005 "0601061602"   .16159777 27 4
    1995 "0601061802"    -.546453 29 4
    2005 "0601061802"   .16159777 36 4
    1995 "0601062002"   .26992753 23 4
    2005 "0601062002"    .9059061 30 4
    1995 "0601062302"    1.869309 26 4
    2005 "0601062302"     -2.9264 33 4
    1995 "0601062802"   -.4743808 21 4
    2005 "0601062802"    .9059061 27 4
    1995 "0601063102"   -.4743808 23 4
    2005 "0601063102"   1.6139568 28 4
    1995 "0601065402"   .16159777 28 4
    2005 "0601065402"   1.7972366 34 4
    1995 "0601067002"   .16159777 31 4
    2005 "0601067002"    .9059061 38 4
    1995 "0601069302"  -1.1437391 31 4
    2005 "0601069302"    .3419997 37 4
    1995 "0601070202"   -.4743808 19 4
    2005 "0601070202"    .8696486 25 4
    1995 "0601070802"   .26992753 27 4
    2005 "0601070802"     -2.9264 34 4
    1995 "0601071402"    .9059061 26 4
    2005 "0601071402"   .16159777 41 4
    1995 "0601071502"   .16159777 29 4
    2005 "0601071502"   1.0529283 35 4
    1995 "0601071602"   .16159777 28 4
    2005 "0601071602"   .26992753 34 4
    1995 "0601071702"   .16159777 27 4
    2005 "0601071702" -.018804206 32 4
    1995 "0601072002"   1.5418847 30 4
    2005 "0601072002"   -.3994308 36 4
    1995 "0601072702"    2.613617 19 4
    2005 "0601072702"    1.869309 25 4
    1995 "0601072902"   1.7972366 30 4
    2005 "0601072902"    2.613617 41 4
    1995 "0601073102"   .26992753 27 4
    2005 "0601073102"    .9808561 34 4
    1995 "0601074202"    .9059061 22 4
    2005 "0601074202"   -.3273586 29 4
    1995 "0601074502"   .26992753 25 4
    2005 "0601074502"   .16159777 31 4
    1995 "0601075502"   -.6547828 22 4
    2005 "0601075502"   .16159777 28 4
    1995 "0601075902"   1.0529283 36 4
    2005 "0601075902"    2.613617 37 4
    1995 "0601077402"   .16159777 38 4
    2005 "0601077402"    .3419997 31 4
    1995 "0601078802"   .16159777 37 4
    2005 "0601078802"    .9779783 43 4
    1995 "0601079402"   .16159777 31 4
    2005 "0601079402"   .16159777 38 4
    1995 "0601079502"   .16159777 30 4
    2005 "0601079502"   1.7972366 38 4
    1995 "0601080302"     -2.9264 20 4
    2005 "0601080302"     -2.9264 27 4
    1995 "0601081102"   -.4743808 24 4
    2005 "0601081102"     -2.9264 30 4
    1995 "0601082202"   1.6139568 29 4
    2005 "0601082202"   -1.399091 36 4
    1995 "0601082402"  -2.2904217 38 4
    2005 "0601082402"   .16159777 44 4
    1995 "0601083402"   -2.182092 26 4
    2005 "0601083402"   -.4743808 33 4
    1995 "0601084002"   .16159777 35 4
    2005 "0601084002"   1.7972366 42 4
    1995 "0601084502"   1.0529283 41 4
    2005 "0601084502"    2.613617 46 4
    1995 "0601084902"     -2.9264 32 4
    2005 "0601084902"   3.2495956 38 4
    1995 "0601085202"   .16159777 20 4
    2005 "0601085202"    1.869309 26 4
    end
    label values region region
    label def region 4 "Urban Governorates", modify

    Thanks.





  • #2
    Did you perhaps write your code in Word or some other program intended for producing "writing" rather than code?

    Stata has told you exactly what is wrong - the character you believe is a "minus sign" is not recognized by Stata - it is in fact a typographical en-dash. When I type your code into Word, it autocorrects the minus sign I type into the en-dash. I pasted your incorrect code into the do-file editor and replaced the en-dash with a minus sign and the error went away.

    Using Word to edit code is a terrible idea and if that is what you are doing, I encourage you to stop doing so. Instead, use Stata's do-file editor, or else use some other "text editor" like BBedit (macOS) or vi (Linux) or whatever is appropriate on Windows to create your programs.

    Comment


    • #3
      Sherine:
      you may want to try:
      Code:
      bysort Findid: g Diff_degre=degre[2]-degre[1] if _n==2
      PS: crossed in the cyberspace with William's interesting point.
      Kind regards,
      Carlo
      (Stata 18.0 SE)

      Comment


      • #4
        I didn't realise that could happen, typing out the code into stata directly has resolved the problem! Will take that advice on board.

        Thank you William and Carlo.

        Comment

        Working...
        X