Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Panelvar

From   Natalie Trapp <>
Subject   Re: st: Panelvar
Date   Fri, 06 Aug 2010 10:11:30 +0200

On 8/6/2010 10:00 AM, Hobst wrote:

  I have a panaldata set. I want to use the brandnames as the panel ID
variable, but obviously Stata doesnt accpet a string variable as the panel
ID var. How can i create a variable that defines a unique numbre for every
brand name so i can use it as the panel ID var for my paneldata?

Thanks a lot for your help.

Hi Toby,

I would first encode the string variable:

*encode varname, generate(newvarname)

then I would use "forvalues"

*sort  newvarname
*gen individual = .
*gen newvarname_lag = newvarname[_n-1]
*local number = 1
*replace individual = `number'  in 1
*local anzahl = _N
*forvalues i = 2/`anzahl' {
*replace individual = `number'  + 1 in `i'
*replace individual = `number'  if newvarname== newvarname_lag  in `i'
*local number = individual[`i']
*drop  newvarname_lag

I am sorry, there is most probably a much more simple way to do it, but I wrote this when I had to identify individuals over more than one variable. I hope this helps you.


Natalie Trapp

Research Unit Sustainability and Global Change
Centre for Marine and Atmospheric Sciences
Hamburg University
Bundesstraße 55
D-20146 Hamburg

PhD student at the International Max Planck
Research School on Earth System Modeling

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index