Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Balancing panel data uniquely identified by TWO variables
From
Victor Gauto <[email protected]>
To
[email protected]
Subject
st: Balancing panel data uniquely identified by TWO variables
Date
Sat, 6 Nov 2010 21:42:43 -0500
Dear Statalist,
I have an unbalanced panel I would like to “fill” out. I’ve tried
using the “tsset” and “tsfill, full” commands without getting the
results I wanted. As an example, I have 2 companies selling 2
products in 3 years. So if my data were complete I should have
2X2X3=12 observations to have a balanced panel. I have fewer
observations, since some companies have not sold all the products in
all the years. For example, I have 7 observations. I would like to
fill this gap by including missing observations due to lack of sales
of certain products, or certain years.
The tsset syntax looks like this (I realize this may also be done with xtset):
"tsset panelvar timevar"
I think my panelvar is actually made up of two variables (company and
product; which are also unbalanced in my data), so I’m not sure how to
work around this.
I have tried the following:
sort year company_id product_id
gen panel_id=_n
tsset panel_id year
tsfill, full
I do not think this does it because "panel_id" above includes the year
dimension and goes from 1-7. As a result, the code above OVERfills my
data. Instead of getting the desired 12 observations, I get 7X3=21
observations, which is not what I want.
I want to go from this:
Year Company_ID Product_ID Sales Yearly Profits n
1980 1 1 250 5000 1
1981 1 1 225 2000 2
1982 1 1 120 1200 3
1981 1 2 125 2000 4
1980 2 1 250 1600 5
1981 2 2 450 1700 6
1982 2 2 300 2200 7
TO THIS:
Year Company_ID Product_ID Sales Yearly Profits n
1980 1 1 250 5000 1
1981 1 1 225 2000 2
1982 1 1 120 1200 3
1980 1 2 . 5000 4
1981 1 2 125 2000 5
1982 1 2 . 1200 6
1980 2 1 250 1600 7
1981 2 1 . 1700 8
1982 2 1 . 2200 9
1980 2 2 . 1600 10
1981 2 2 450 1700 11
1982 2 2 300 2200 12
Many thanks for any help,
Victor
*
* 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/