- Thread starter abc
- Start date

tsset country year

gen diff_CPI = D.xCPI

and what I get is the same main variable data without the first year observation. In other worlds

year CPI DCPI

1990 7.27226

1991 3.22268 7.27226

1992 0.985915 3.22268

1993 1.81311 0.9859155

1994 1.89498 1.81311

1995 4.63814 1.894977

1996 2.61242 4.638136

1997 0.250417 2.61242

A you can see this is not a first difference , I get for the CPI variable and the 1991 year data the observation that was for 1990c instead of getting their difference. This goes for all data and counties .I repeat tat I work on a macro panel that contains 55 countries for a time length of about 20 years and need the first difference of a number of variables.

Thanks

abc..

I don't see anything wrong with Maarten's solution, but I don't

have your data to allow me to do any diagnosis.

Anyway, you may want to read the advice on first-differences from Austin Nichols

on StataList at http://www.stata.com/statalist/archive/2011-09/msg00680.html.

have your data to allow me to do any diagnosis.

Anyway, you may want to read the advice on first-differences from Austin Nichols

on StataList at http://www.stata.com/statalist/archive/2011-09/msg00680.html.

Last edited:

Here is a toy example of Maarten's approach.

Note that tsset can only accept numeric variables, so

you need a numeric variable for country.

Note that tsset can only accept numeric variables, so

you need a numeric variable for country.

Code:

```
clear
input str2 country year x
US 1990 7.27226
DE 1990 3.22268
US 1991 0.985915
DE 1991 1.81311
US 1992 1.89498
DE 1992 4.63814
US 1993 2.61242
DE 1993 0.250417
end
* tsset variables must be numeric
* so this creates numeric code for country
encode country, gen(ccode)
list
tsset ccode year
gen diff_x = D.x
list
```

Last edited:

have your data to allow me to do any diagnosis.

Anyway, you may want to read the advice on first-differences from Austin Nichols

on StataList at http://www.stata.com/statalist/archive/2011-09/msg00680.html.

Yes this one works like a charm! Having missing values in the time variable in my panel I managed to solve by running this command

tsset ccode year

g Dx = x-L.x