Quantcast

Panelvar

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Panelvar

Hobst
Hello

 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.

Regards
Toby
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: Panelvar

Martin Weiss-5

<>

Maybe

*************
encode
*************

it beforehand.


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Hobst
Gesendet: Freitag, 6. August 2010 10:00
An: [hidden email]
Betreff: st: Panelvar

Hello

 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.

Regards
Toby
--
View this message in context:
http://statalist.1588530.n2.nabble.com/Panelvar-tp5379648p5379648.html
Sent from the Statalist mailing list archive at Nabble.com.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Panelvar

Natalie Trapp
In reply to this post by Hobst
On 8/6/2010 10:00 AM, Hobst wrote:

> Hello
>
>   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.
>
> Regards
> Toby
>    
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.

regards,
natalie

--
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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: st: Panelvar

Martin Weiss-5

<>


I think -encode- is all Toby needs:


*************
clear*

inp str11 brand int year
firstbrand 1990
firstbrand 1991
firstbrand 1992
secondbrand 1990
secondbrand 1991
secondbrand 1992
end

list, noo

//does not work
cap noi xtset brand year

//does work...
encode brand, gen(numericbrand)
xtset numericbrand year
*************

What is the rest of your code meant to do, Natalie?


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Natalie Trapp
Gesendet: Freitag, 6. August 2010 10:12
An: [hidden email]
Betreff: Re: st: Panelvar

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

> Hello
>
>   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.
>
> Regards
> Toby
>    
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.

regards,
natalie

--
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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AW: st: Panelvar

Hobst
Thank you both very much for the fast response. I will try it and report back.

Regards
Toby



Am 06.08.2010 um 10:21 schrieb "Martin Weiss" <[hidden email]>:

>
> <>
>
>
> I think -encode- is all Toby needs:
>
>
> *************
> clear*
>
> inp str11 brand int year
> firstbrand 1990
> firstbrand 1991
> firstbrand 1992
> secondbrand 1990
> secondbrand 1991
> secondbrand 1992
> end
>
> list, noo
>
> //does not work
> cap noi xtset brand year
>
> //does work...
> encode brand, gen(numericbrand)
> xtset numericbrand year
> *************
>
> What is the rest of your code meant to do, Natalie?
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von Natalie Trapp
> Gesendet: Freitag, 6. August 2010 10:12
> An: [hidden email]
> Betreff: Re: st: Panelvar
>
> On 8/6/2010 10:00 AM, Hobst wrote:
>> Hello
>>
>>  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.
>>
>> Regards
>> Toby
>>
> 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.
>
> regards,
> natalie
>
> --
> 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:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AW: st: Panelvar

Natalie Trapp
In reply to this post by Martin Weiss-5
I thought my code could also work for generating an individual variable
for Tobias brand names, but I noticed encode is sufficient already.
I used it for my panel data set to generate a unique identification for
surveyed European farms depending on certain characteristics such as
region, sub region, farm type, farm size, etc. but it is redundant in
the brand names case. Sorry!

On 8/6/2010 10:21 AM, Martin Weiss wrote:

> <>
>
>
> I think -encode- is all Toby needs:
>
>
> *************
> clear*
>
> inp str11 brand int year
> firstbrand 1990
> firstbrand 1991
> firstbrand 1992
> secondbrand 1990
> secondbrand 1991
> secondbrand 1992
> end
>
> list, noo
>
> //does not work
> cap noi xtset brand year
>
> //does work...
> encode brand, gen(numericbrand)
> xtset numericbrand year
> *************
>
> What is the rest of your code meant to do, Natalie?
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von Natalie Trapp
> Gesendet: Freitag, 6. August 2010 10:12
> An: [hidden email]
> Betreff: Re: st: Panelvar
>
> On 8/6/2010 10:00 AM, Hobst wrote:
>    
>> Hello
>>
>>    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.
>>
>> Regards
>> Toby
>>
>>      
> 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.
>
> regards,
> natalie
>
>    



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: AW: st: Panelvar

Martin Weiss-5

<>

" I used it for my panel data set to generate a unique identification for
surveyed European farms depending on certain characteristics such as
region, sub region, farm type, farm size, etc. but it is redundant in
the brand names case."


I am guessing, admittedly, but

*************
egen, group()
*************

may well serve you better, then...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Natalie Trapp
Gesendet: Freitag, 6. August 2010 10:53
An: [hidden email]
Betreff: Re: AW: st: Panelvar

I thought my code could also work for generating an individual variable
for Tobias brand names, but I noticed encode is sufficient already.
I used it for my panel data set to generate a unique identification for
surveyed European farms depending on certain characteristics such as
region, sub region, farm type, farm size, etc. but it is redundant in
the brand names case. Sorry!

On 8/6/2010 10:21 AM, Martin Weiss wrote:

> <>
>
>
> I think -encode- is all Toby needs:
>
>
> *************
> clear*
>
> inp str11 brand int year
> firstbrand 1990
> firstbrand 1991
> firstbrand 1992
> secondbrand 1990
> secondbrand 1991
> secondbrand 1992
> end
>
> list, noo
>
> //does not work
> cap noi xtset brand year
>
> //does work...
> encode brand, gen(numericbrand)
> xtset numericbrand year
> *************
>
> What is the rest of your code meant to do, Natalie?
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von Natalie Trapp
> Gesendet: Freitag, 6. August 2010 10:12
> An: [hidden email]
> Betreff: Re: st: Panelvar
>
> On 8/6/2010 10:00 AM, Hobst wrote:
>    
>> Hello
>>
>>    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.
>>
>> Regards
>> Toby
>>
>>      
> 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.
>
> regards,
> natalie
>
>    



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AW: AW: st: Panelvar

Natalie Trapp
Thank you Martin. I will keep it in mind for the future ;o)

On 8/6/2010 10:59 AM, Martin Weiss wrote:

> <>
>
> " I used it for my panel data set to generate a unique identification for
> surveyed European farms depending on certain characteristics such as
> region, sub region, farm type, farm size, etc. but it is redundant in
> the brand names case."
>
>
> I am guessing, admittedly, but
>
> *************
> egen, group()
> *************
>
> may well serve you better, then...
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von Natalie Trapp
> Gesendet: Freitag, 6. August 2010 10:53
> An: [hidden email]
> Betreff: Re: AW: st: Panelvar
>
> I thought my code could also work for generating an individual variable
> for Tobias brand names, but I noticed encode is sufficient already.
> I used it for my panel data set to generate a unique identification for
> surveyed European farms depending on certain characteristics such as
> region, sub region, farm type, farm size, etc. but it is redundant in
> the brand names case. Sorry!
>
> On 8/6/2010 10:21 AM, Martin Weiss wrote:
>    
>> <>
>>
>>
>> I think -encode- is all Toby needs:
>>
>>
>> *************
>> clear*
>>
>> inp str11 brand int year
>> firstbrand 1990
>> firstbrand 1991
>> firstbrand 1992
>> secondbrand 1990
>> secondbrand 1991
>> secondbrand 1992
>> end
>>
>> list, noo
>>
>> //does not work
>> cap noi xtset brand year
>>
>> //does work...
>> encode brand, gen(numericbrand)
>> xtset numericbrand year
>> *************
>>
>> What is the rest of your code meant to do, Natalie?
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email]
>> [mailto:[hidden email]] Im Auftrag von Natalie Trapp
>> Gesendet: Freitag, 6. August 2010 10:12
>> An: [hidden email]
>> Betreff: Re: st: Panelvar
>>
>> On 8/6/2010 10:00 AM, Hobst wrote:
>>
>>      
>>> Hello
>>>
>>>     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.
>>>
>>> Regards
>>> Toby
>>>
>>>
>>>        
>> 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.
>>
>> regards,
>> natalie
>>
>>
>>      
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>    


--
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

Telephone  +49 (0)40 428384121
Telefax    +49 (0)40 428387009
E-mail     [hidden email]


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Loading...