Practical tips for statisticians (part 8): centering variables using Stata and SPSS

My current research requires meta-analytic procedures where variables that contain another variable’s mean come in very handy. Centering Variables is also something very reasonable to do when analysing regressions with an interaction term between a continuous variable and a dummy variable.

Centering variables sounds like an easy task. It is if you use Stata but I found it surprisingly difficult in SPSS (unless you enter the means by hand, which is error-prone and impractible for repeated analyses). Here’s how you can calculated a variable which contains the mean of another variable (which can then easily be centered or used in whatever way one wants to).

Let dres be the variable of interest. The new variable containing the mean of dres (for all obversations) will be named dresavg. I also show how to create a variable containing the number of observations (ntotal). cdres will be the centered variable.

Stata 10

Use

. egen dresavg = mean(dres)

and you’re done! You could also use summarize and generate commands:

. sum dres
. gen dresavg = r(mean)

If you want a variable that contains the total number of observations you can use

. gen ntotal = _N

or with the more flexible egen command (e.g., handy when dres has missings)

. egen ntotal = count(dres)

There are plenty ways to generate various variables containing sample statistics. As for the centered variable, use

. gen cdres = dres - dresavg

or without even generating the variable containing the mean:

. sum dres
. gen cdres = dres - r(mean)

PASW 18 (SPSS, you know)

Beware, long syntax ahead. Before you despair, there’s a simpler (but less flexible) solution below. The complicated approach starts with exporting the variable mean into a new data set. This data set is then merged with the master data set; a variable containing the mean for every observation will be attached. Read the rest of this entry »

Jutze 52 #35 – Old McBiddy’s Wedding

This is a nod to my dark progressive country roots. And to Old McBiddy, who’s living happily on his farm in Scotland. (O hai, video!)

#35 Old McBiddy’s Wedding

People came from far to see Old McBiddy’s wedding
Gather in the churchyard to celebrate the day
Oh what a joy it’s going to be: Old McBiddy’s wedding
So when he says, I do, the crowd shouts out, hooray!
Now we’re going to celebrate Old McBiddy’s wedding
Hurry boys, do not be late and let the music play

Watch the people as they dance at Old McBiddy’s wedding
Meanwhile Uncle Parker is getting drunk on wine
Come on folks, raise your hands at Old McBiddy’s wedding
Toast to the happy couple and their love divine

(words and music by Johannes Schult)

Jutze 52 #34 – Big in Serbia

This is the first proper song I’ve recorded on my new computer. I still have a couple of digicam tracks which I’ll feature here, eventually. I had to force myself rather hard to create this particular song here. Thankfully, Russ chimed in with the suggestion to write about Tropical Heat’s popularity in Serbia. I pieced a few riffs together and assembled the lyrics on the fly, based on a few key words I had jotted down earlier. The whole thing would deserve a more elaborate song. But I only had a narrow time window this week and I was eager to experiment with the new recording software. I hope, however, that the song fits with the other 52-second songs I’ve done so far. (An epic instrumental MIDI-suite is in the works but that’s a different story – related to hybris.)

Želim da postanem poznata u SrbiJa. Ugoditi pomoc mene. Hvala. Ljubav i palacinke!

#34 Big in Serbia

I don’t expect to become an internet superstar
But I wouldn’t mind a bit more popularity
I wish I was big in Serbia
That people recognized me in the street
I wish I was big in Serbia
Just like Tropical Heat

(words and music by Johannes Schult)

Jutze 52 #33 Regentropfen im Nordwind

This little tune was written and recorded at an unlikely location: the camping ground of this year’s Headbangers Open Air. I had planned to record more tracks back home. But once I had come up with the melody I liked the sparse sound of the glockenspiel. I recorded the song with my digicam inside the car. I had to close the windows because the first band of the day was already on stage, thrashing away. It got quite hot. So for me it’s surprising how the track sounds nothing like the circumstances under which it came into being.

#33 Regentropfen im Nordwind

Jutze 52 #32 – Hank Green Learned a New Chord

This is a song about F-sharp minor (as seen in Hank’s video around 2:25). If you don’t know who Hank Green is, check out his music at DFTBA Records.

“Hank Green Learned a New Chord” is yet another example for songs I hadn’t written without the 52-second constraint (and the need for brief song lyrics associated with it). Once again I had to record everything with my digicam, hence the bad sound. On the bright sight, you can watch me playing/recording the song.

#32 Hank Green Learned a New Chord

It was Wednesday the 21st
Hank played a tune on his guitar
There on the vlogbrothers channel
I almost couldn’t believe what I saw
It was like an epiphany
Though the part was rather short
It was plain for all to see
Hank Green learned a new chord

Until that day I had always thought
That Hank was a Horcrux of punk
A way to keep the lore of the three chord songs
Safe from boy-groups and funk
It was like an epiphany
Though the part was rather short
It was plain for all to see
Hank Green learned a new chord

Is he about to make the transition from wizard rock
To Slytherin Jazz for the Dark Lord?
Hank Green learned a new chord

(words and music by Johannes Schult)

Jutze 52 #31 – Rainy Day

This is the result of my overexposure to Star Wars. In a post-“Return of the Jedi” world I can imagine guided tourist tours over the Endor battlefield. Who needs Gettysburg when you can stroll through the ruins of the shield generator? Speeder bikes available for extra charge. Yet, given the vast green forests on Endor it must be raining rather often.

The lyrical idea and the main melody lay around for a while until I figured I’d use my digicam to capture me recording the individual parts. I completed the lyrics in a hurry, scrapping my otherwise favourite line “Like a rainy day on Endor with no fur to keep you warm”. The audio tracks are actually those from the camera, so please excuse the crappy quality. You can see excerpts from all five tracks in the video.

#31 Rainy Day

Now I’ve finally reached my aim
But it really ain’t the same
Without you by my side
Feels like a rainy day on Endor
Feels like a rainy day on Endor

I can’t enjoy my victory
Because I was too blind to see
Just what you meant to me
Feels like a rainy day on Endor
Feels like a rainy day on Endor

(words and music by Johannes Schult)

Soccer Girl

This is my new single! It consists of two short songs. Check out jutze.bandcamp.com for further song details, full-length audio samples and various download options. NB: You can download the songs for free by entering zero Euros (0.00€) when naming your price.

Jutze 52 #30 – Der Speckgürtel von Paderborn

This song is rather weird.

#30 Der Speckgürtel von Paderborn

Ein schwarzer VW-Bus hielt vor meinem Haus
Und eh ich mich versah, stiegen schwarze Leute aus
Der erste Vermummte hatte ein Gewehr
Er legte an und schoss und mein Körper wurde schwer
Getroffen!

Der zweite Vermummte griff nach meinem Bein
Und zu zweit hievten sie mich dann in den Bus hinein
Ich verlor das Bewusstsein wie in einem schlechten Traum
Und ich wachte wieder auf in einem fensterlosen Raum
Gefangen!

Dann kam ein Mann im weißen Kittel mit Blutflecken drauf
Er zerrte mich nach nebenan; ich stolperte im Lauf
Ich kann nur schwer beschreiben, was daraufhin geschah
Man zwickte und massierte mich und spielte danach Skat

Man schnürte mich auf Rollschuh und man drehte mich im Kreis
Man kniff mich in mein Ohrläppchen und fragte, wie ich heiß
So ging das viele Stunden und ich war total verwirrt
Ich konnte nicht entfliehen; ich war allein und sie zu viert
Gefangen!

Ich kann mich nicht erinnern, doch plötzlich war es aus
Und müde lag ich auf dem Rasen hier vor meinem Haus
Ich zitterte und fror und meine Kehle brannte
Und dann fiel mir wieder ein, wie der Ort sich nannte
Speckgürtel von Paderborn!

(words and music by Johannes Schult)

Jutze 52 #29 – Your Smile

This is the last song I recorded on my old computer. I wanted to approach the 52 seconds of music without a regular song structure in mind. I combined various parts and slowly the track grew into what you hear now. The lyrics had no meaning at first but after tweaking a few lines a vague situation came to life. I also recorded a quick video of me playing the song.

#29 Your Smile

You said goodbye with a hint of regret in your smile
And finally I see that I am free
Because what you meant to me
Won’t bother me no more
It’s all I had in store
And the times we spent
Trying to meet ends meet
It feels so obsolete
And I bleed
I wonder why I liked your smile
Your smile
Your smile

(words and music by Johannes Schult)

Toto live in Singen

Last night, Toto played at the Hohentwiel Festival in Singen. Now the Hohentwiel is an elevation about 250 m above the city. So when I arrived at the station (after cycling to the station in Konstanz and then taking the train to Singen) I was 250 horizontal meters away from the festival site. And 250 vertical meters. There was a bus service that took you halfway up the hill. I opted to walk the whole way, partly because the scenery was very beautiful, partly because I wanted to figure out the way back at night. Also, the bus shuttle queue wasn’t short. Arriving at the top I was in need of quite some water. I was also intrigued by the unconventional setting: the yard of the castle ruin seemed terribly small and rather askew in some places. (The opening band wasn’t particularly interesting to my ears.)

Toto started out with “Child’s Anthem”. The audience was immediately hooked. The sound was clear and thankfully not too loud. I still find the refrain of “Till the End” to be an anticlimax. But apart from that, the music, the atmosphere, the band and the audience were great! Steve Porcaro seemed to get a real kick out of performing live. He had his shirt wet with sweat after four songs already. David Paich throned on the opposite side of the stage and sported a hat and a gown along with short trousers. It was good to see him back in the limelight. His playing was fantastic and his voice, while not being very versatile, had the special vibe that worked so well in songs like “Lovers in the Night” and later on “Home of the Brave”. I hadn’t hope to see Joseph Williams back with Toto but there he was! Given the occasion the band included the two albums with Williams. “Pamela” and “Stop Loving You” were perfect pop songs. I dare to say you cannot play that type of music any better. Period. There were also less famous tracks like “Stay Away” and “Lea”, which were just great. I was very glad to have songs like these in the set instead of medleys or a simple collection of tracks that had been released as singles. My personal favourite was “I Will Remember”, the only song played that was released after 1988. I still regard it as one of the best songs ever written and the rendition in Singen was just sublime.

By the time the band played “Africa” the hot sun had given way to a thunderstorm. Rain started pouring and I don’t think many people blessed the rains up in Singen at that time. A few rows in front of the stage (where I stood) where able to find shelter under the roof of the stage. Unfortunately, the water caught by said roof came down unto the audience behind the first rows. So from then on there was a divide caused by this waterfalls. I was surprised that the change of weather didn’t diminish the applause and the enthusiasm of the audience.

“Hold the Line” was inevitable. Some of the previous songs had been extended with jams and sing-along parts, so was quite happy the band kept the song in its original short form. Of course, I would have loved to hear “Mushanga”, “Straight for the Heart”, “Bottom of Your Soul” and many other songs. But the actual set list was satisfying and who knows if Toto will ever come on tour again?

Rain in Singen

  1. Child’s Anthem
  2. Till the End
  3. Afraid of Love
  4. Lovers in the Night
  5. Pamela
  6. Lea
  7. 99
  8. Stay Away
  9. I Will Remember
  10. Africa
  11. Somewhere Tonight
  12. Georgy Porgy
  13. Stop Loving You
  14. Rosanna
  15. Home of the Brave
  16. Hold the Line