Statalist


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

Re: st: creating a numeric matrix from string variables


From   joe j <joe.stata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: creating a numeric matrix from string variables
Date   Thu, 4 Jun 2009 22:57:33 +0200

Thanks so much, Bill.

What the first part of your coding produced was exactly what I was
looking for. You are probably right that this not the best way to
store data. However, I have not been able to figure out how keeping
the data in the long form would make it easy for me to merge  it with
other firm-level variables. Let's say I have data on two firm-level
variables "sales" and "profit" which look as follows:
Company	Sales Profit
11A	        100	10
11K	        200	30
12Z	        500	100
14T	        400	150
21S	       300	250

I can now easily merge this to the matrix, using the common variable
in both the data "Company". Now why do I want to combine these two
data sets? One reason. When I remove some firms from the data set
because, for example, they are too small (small volumes of sales), I
can easily make those changes in the matrix as well (because there is
one common company id for both the matrix and other variables). I'd
not in any case do matrix-based computations in Stata, but I'd use
some social network program to analyze the matrix and derive certain
network measures, which will then be brought back to Stata for
analysis, along with other firm-level variables. This is how I saw the
way to proceed, . But I've never used this type of data before, so I
think I am perhaps missing your point big time and therefore I'll
think further over your suggestion.

Thanks,
Joe.


On Thu, Jun 4, 2009 at 4:09 PM, William Gould, StataCorp LP
<wgould@stata.com> wrote:

> I wonder whether Joe really wants that because I suspect that is not a
> useful way to store or analyze these data, but I may be wrong, so
> first, let's get the data organized in this way.
>
>
> Obtaining what Joe wants
> ------------------------
>
>
>
>             +-------------------------------------------------+
>             | company   f_11A   f_11K   f_12Z   f_14T   f_21S |
>             |-------------------------------------------------|
>          1. |     11A       0       0       2       1       0 |
>          2. |     11K       0       0       1       0       1 |
>          3. |     12Z       2       1       0       1       1 |
>          4. |     14T       1       0       1       0       0 |
>          5. |     21S       0       1       1       0       0 |
>             +-------------------------------------------------+
>
>
> How I would organize these data
> -------------------------------
>
> I would organize these data in the long form, like this,
>
>             +-----------------------------------+
>             | c1   c2   company1   company2   n |
>             |-----------------------------------|
>          1. |  1    2        11A        11K   0 |
>          2. |  1    3        11A        12Z   2 |
>          3. |  1    4        11A        14T   1 |
>          4. |  1    5        11A        21S   0 |
>          5. |  2    3        11K        12Z   1 |
>             |-----------------------------------|
>          6. |  2    4        11K        14T   0 |
>          7. |  2    5        11K        21S   1 |
>          8. |  3    4        12Z        14T   1 |
>          9. |  3    5        12Z        21S   1 |
>         10. |  4    5        14T        21S   0 |
>             +-----------------------------------+
>

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



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