[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <[email protected]> |

To |
<[email protected]> |

Subject |
RE: st: How to append two columns |

Date |
Thu, 4 Sep 2008 15:23:33 +0100 |

So long as it works, no one is going to mind much! I just underline as a general message that knowing Stata functions (strict sense) well gives you lots of control, especially for (what look like) non-standard problems. There is a strange widespread bias that there should be a command for everything. It is true that commands are at the heart of Stata, but they aren't the only way to proceed. I once floated the idea of a Stata training course going through the functions with lots of examples, particularly in terms of combining functions. It would probably be the least exciting and most tedious Stata course imaginable, but I think a lot of Stata users would realise how much they were missing. Nick [email protected] John Ataguba Thanks Nick. The -egen newvar=concat(varlist) is more generic for me and will do. This is because you can combine it with destring if it was initially numeric. --- On Thu, 4/9/08, Nick Cox <[email protected]> wrote: > From: Nick Cox <[email protected]> > Subject: RE: st: How to append two columns > To: [email protected] > Date: Thursday, 4 September, 2008, 3:46 PM > But there is a command to do it. This crossed with my post > pointing that out. It is -egen, concat()-. Or alternatively > this is possible with basic functions: > > gen var12 = real(string(var1) + string(var2)) > > or > > gen var12 = string(var1) + string(var2) > > or > > gen var12 = real(var1 + var2) > > or > > gen var12 = var1 + var2 > > depending on what you have and what you want. (Your > question did not specify whether you had numeric or string > variables.) > > Nick > [email protected] > > John Ataguba > > Thanks Johannes and Ashim. The suggestions were great. I > thought there could be a command to just do this without > going through manipulations. > > Johannes Geyer > > > You could generate strings from your numeric > variables, > > add them together and convert the string back to > numeric: > > > > ******************* > > clear > > set obs 10 > > gen x = _n * 1000 > > gen y = _n > > > > tostring x, generate(a) > > tostring y, generate(b) > > gen z = a + b > > destring z, replace > > > > ****************************** > > > > Ashim > > > > A crude way would be to multiply the 1st column > by 10 > > and add the 2nd > > > column to it ? > > John Ataguba > > > > > I am trying to append two colums in stata > and I > > was wondering if > > > this is possible. Basically I have data in the > > following way > > > > > > > > UQNo PersonNo > > > > 100012 1 > > > > 100012 2 > > > > 100012 3 > > > > 100024 1 > > > > 100024 2 > > > > 100019 1 > > > > 100019 2 > > > > 100019 3 > > > > 100055 1 > > > > 100075 1 > > > > 100075 2 > > > > > > > > And I want to generate a new variable that > will > > look like > > > > > > > > UQNoP > > > > 1000121 > > > > 1000122 > > > > 1000123 > > > > 1000241 > > > > 1000242 > > > > 1000191 > > > > 1000192 > > > > 1000193 > > > > 1000551 > > > > 1000751 > > > > 1000752 > * * 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/

**References**:**RE: st: How to append two columns***From:*"Nick Cox" <[email protected]>

**RE: st: How to append two columns***From:*John Ataguba <[email protected]>

- Prev by Date:
**Re: st: Treating multiple-variables as one** - Next by Date:
**st: RE: Using Gr39** - Previous by thread:
**RE: st: How to append two columns** - Next by thread:
**RE: st: How to append two columns** - Index(es):

© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |