[R] create a dummy variables for companies with complete history.

Sarah Goslee sarah.goslee at gmail.com
Wed Jun 24 20:49:00 CEST 2015


Please repost your question in plain text rather than HTML - you can
see below that your code got rather mangled. Please also include some
sample data using dput() - made-up data of similar form is fine, but
it's very hard to answer a question based on guessing what the data
look like.

Sarah

On Wed, Jun 24, 2015 at 2:26 PM, giacomo begnis <gmbegnis at yahoo.it> wrote:
> Hi, I have a dataset  (728 obs) containing three variables code of a company, year and revenue. Some companies have a complete history of 5 years, others have not a complete history (for instance observations for three or four years).I would like to determine the companies with a complete history using a dummy variables.I have written the following program but there is somehting wrong because the dummy variable that I have create is always equal to zero.Can somebody help me?Thanks, gm
>
> z<-read.table(file="c:/Rp/cddat.txt", sep="", header=T)
> attach(z)
> n<-length(z$cod)  // number of obs dataset
>
> d1<-numeric(n)   // dummy variable
>
> for (i in 5:n)  {
>    if (z$cod[i]==z$cod[i-4])             // cod is the code of a company             { d1[i]<=1} else { d1[i]<=0}          // d1=1 for a company with complete history, d1=0 if the history is not complete  }d1
> When I run the program d1 is always equal to zero. Why?
> Once I have create the dummy variable with subset I obtains the code of the companies with a complete history and finally with a merge  I determine a panel of companies with a complete history.But how to determine correctly d1?My best regards, gm
>
>
>
>         [[alternative HTML version deleted]]
>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list