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 |
Eric Booth <ebooth@ppri.tamu.edu> |

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

Subject |
Re: st: Re: Equivalent to matcell in table |

Date |
Wed, 14 Jul 2010 15:37:22 +0000 |

<> > > I tried the following: > reshape wide table1, i(Traded_Model) j(NewModel) string > Then i get the error message Table12.3CL invalid name. Any suggestions where i am wrong? > You can't have a variable name with a period "." in it. See "help varname". You can subinstr() the period. The data transformation you request in your posting below doesn't match your next posting with the .png images. In the post below you've got indicators of the traded_models (1/0) after the reshape, but in the png files you've got some kind of count (?) of the traded_models after the reshape. Here's a guess at what you might be looking for. If not, please provide a more clear example/explanation. ****************! //this first section creates the fake dataset you provided: **run this in a new do-file editor window** clear inp str15(newmodel traded_model) table1 "expedition" "2.3CL" 1 "montero_sport" "2.3CL" 1 "200SX" "200SX" 1 "4Runner" "200SX" 1 "626" "200SX" 2 "accord" "200SX" 2 "alero" "200SX" 1 "expedition" "200SX" 1 "expedition" "200SX" 1 end //this cleans up the newmodel and traded_model vars: replace newmodel = subinstr(newmodel, "_", " ", .) replace newmodel = proper(newmodel) replace traded_model = subinstr(traded_model, ".", "_", .) //next, you need some identifiers to reshape with: **see help reshape g id = _n bys traded_: g modelid_ = _n //reshape: reshape wide modelid_, i(id) j(traded_) string order newmodel drop id //change to 1's and 0's: recode modelid_* (.=0) (1/max = 1) /* This next section assumes that you want to get this data to one record per newmodel, and in doing so, that you want some kind of: (1) indicator that the traded_model was traded for the newmodel, or (2) count of the number of traded_models traded for each new model */ ds modelid_* foreach v in `r(varlist)' { **count of traded_models by newmodel** bys newmodel: egen `v'_count = total(`v') ** indicate if each traded_model = 1** bys newmodel: egen `v'_m = max(`v') replace `v' = `v'_m if `v' < `v'_m drop `v'_m } duplicates drop newmodel, force li, noobs clean ****************! ~ Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu Office: +979.845.6754 On Jul 14, 2010, at 7:00 AM, Tobias Friedli wrote: > This is what i have: > > NewModel Traded_Model table1 > Expedition 2.3CL 1 > Montero_Sport 2.3CL 1 > 200SX 200SX 1 > 4Runner 200SX 1 > 626 200SX 2 > Accord 200SX 2 > Alero 200SX 1 > .... ... ... > > where "table1" are the frequencies > > This is what i want: > > 2.3 CL 200SX ..... > > Expedition 1 1 > Mondeo Sport 1 > 200SX 0 1 > > ...... > > I tried the following: > > reshape wide table1, i(Traded_Model) j(NewModel) string > > Then i get the error message Table12.3CL invalid name. Any suggestions where i am wrong? > > > > > On 14.07.2010, at 13:27, Maarten buis wrote: > >> --- On Wed, 14/7/10, Tobias Friedli wrote: >>> I already have a excel file with all >>> the Solver stuff set up to do some optimization on a log >>> likelihood function derived from the matrix. I would like to >>> do it in Stata, but i am just do not have the skills >>> to programm it in stata, this is why i use excel for the >>> optimization. >> >> That worries me. Regardless of its strenghts and weaknesses, >> Excel just is not made to do this kind of stuff. You really >> really really want to use purpose written software, like Stata, >> to this kind of maximization of the likelihood, it is just >> too easy to get it wrong. >> >> If you want to implement your model in Stata (and I repeat, >> I strongly recommend that you do), than you will want to >> have this book on your desk: >> http://www.stata.com/bookstore/mle.html >> >> In addition, if you can wait a while, during the next Italian >> Stata Users' meeting there will be a course on programming >> in Stata: <http://www.stata.com/meeting/italy10/> >> >>> If i use the -outfile- i get a .txt with some tousend >>> rows and 3 colums. But what i want is to have the matrix (as >>> displayed for -table- , i.e 700 rows and 700 colums). how >>> can i do that? >> >> You will need to use -reshape- to get your data in the right >> format. >> >> Hope this helps, >> Maarten >> >> -------------------------- >> Maarten L. Buis >> Institut fuer Soziologie >> Universitaet Tuebingen >> Wilhelmstrasse 36 >> 72074 Tuebingen >> Germany >> >> http://www.maartenbuis.nl >> -------------------------- >> >> * * 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**:**st: Re: Equivalent to matcell in table***From:*Hobst <tobias.friedli@access.uzh.ch>

**References**:**Re: st: Re: Equivalent to matcell in table***From:*Maarten buis <maartenbuis@yahoo.co.uk>

**Re: st: Re: Equivalent to matcell in table***From:*Tobias Friedli <tobias.friedli@access.uzh.ch>

- Prev by Date:
**st: Choosing the best set of longitude/latitude coordinates from three choices** - Next by Date:
**Re: st: Yet another old thread revisited for celebration purposes** - Previous by thread:
**st: Re: Equivalent to matcell in table** - Next by thread:
**st: Re: Equivalent to matcell in table** - Index(es):