The code works for me -- that is, no error -- with a new kernel (no pre-existing definitions in the kernel).
The use of SetDelayed (:=) for data[n_] means a new data set is generated every time a Manipulate button is clicked. That seems odd to me, but maybe it's what you wanted.
The use of data[[i]] in the definitions of g and g does not match the definition of data[n_]. You probably want something like data[k][[i]], but you'll have to pass k to g.