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, **statalist.org** is already up and running.

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

From |
"Scharnigg, Stan (Stud. SBE)" <s.scharnigg@student.maastrichtuniversity.nl> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: add up variable / quantile |

Date |
Thu, 14 Apr 2011 22:55:24 +0200 |

Sorry that I keep asking such simple questions, but I don't get the right outcome. let's say that var1 has approx. 300.000 observations, and var2 approx 5000 observations. gen var3 = var1 == var2[_n-1] or gen var3 = var1[_n-1] == var2 this command gives all the values of var1 a "0", and the rest a "1". Var1 has 300.000 observations with a value, and approx 2 million with a missing value (.) I just don't understand why Stata gives all the values of var1 a "0" and not just the values which are the same. I tried many different, because I just want to be certain that I didn't make a mistake, but I can't figure this out. I checked the variables and there are lots of matched values between them. I hope you can help me with this. ________________________________________ Van: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] namens Scharnigg, Stan (Stud. SBE) [s.scharnigg@student.maastrichtuniversity.nl] Verzonden: donderdag 14 april 2011 17:55 Aan: statalist@hsphsun2.harvard.edu Onderwerp: RE: st: add up variable / quantile aha, then is that the problem. Because var1 has 2.3 million observations and var2 has 5000 observation. However, the values of var2 are more than once in var1. I am gonna try this, thank you :) ________________________________________ Van: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] namens Nick Cox [njcoxstata@gmail.com] Verzonden: donderdag 14 april 2011 17:32 Aan: statalist@hsphsun2.harvard.edu Onderwerp: Re: st: add up variable / quantile gen var3 = var1 == var2 is certainly a good way to create a variable saying whether two variables are the same. But what do you mean that "this is not working"? Note that -- necessarily -- this syntax compares values in the same observation, and not in different observations. gen var4 = var1 == var2[_n-1] illustrates an extension which may be closer to what you seek. Nick On Thu, Apr 14, 2011 at 4:04 PM, Scharnigg, Stan (Stud. SBE) <s.scharnigg@student.maastrichtuniversity.nl> wrote: > I tried a different approach now. I created two new variables (var1, var2), and I want to use those > two variables to create a third variable (var3). Var3 needs to be "1" if var1 has the same values as var2 > > So I tried this: > gen var3 = 0 > replace var3 = 1 if var1==var2 > > However, this is not working. Is something like this possible in 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/ * * 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/

**Follow-Ups**:**Re: st: add up variable / quantile***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**RE: st: add up variable / quantile***From:*"Scharnigg, Stan (Stud. SBE)" <s.scharnigg@student.maastrichtuniversity.nl>

**RE: st: add up variable / quantile***From:*Nick Cox <n.j.cox@durham.ac.uk>

**RE: st: add up variable / quantile***From:*"Scharnigg, Stan (Stud. SBE)" <s.scharnigg@student.maastrichtuniversity.nl>

**Re: st: add up variable / quantile***From:*Nick Cox <njcoxstata@gmail.com>

**RE: st: add up variable / quantile***From:*"Scharnigg, Stan (Stud. SBE)" <s.scharnigg@student.maastrichtuniversity.nl>

**Re: st: add up variable / quantile***From:*Nick Cox <njcoxstata@gmail.com>

**RE: st: add up variable / quantile***From:*"Scharnigg, Stan (Stud. SBE)" <s.scharnigg@student.maastrichtuniversity.nl>

**Re: st: add up variable / quantile***From:*Nick Cox <njcoxstata@gmail.com>

**RE: st: add up variable / quantile***From:*"Scharnigg, Stan (Stud. SBE)" <s.scharnigg@student.maastrichtuniversity.nl>

- Prev by Date:
**Re: st: RE: Quantile Regression Confidence Intervals** - Next by Date:
**Re: st: match string variables** - Previous by thread:
**RE: st: add up variable / quantile** - Next by thread:
**Re: st: add up variable / quantile** - Index(es):